API /repos​/{owner}​/{repo}​/raw​/{filepath} fails if filepath is 40-char long #7907

Closed
opened 2025-11-02 07:41:07 -06:00 by GiteaMirror · 12 comments
Owner

Originally created by @danielemoroni on GitHub (Sep 29, 2021).

Gitea Version

1.12.3

Git Version

No response

Operating System

No response

How are you running Gitea?

I deployed an official download to my server

Database

No response

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

The Gitea API GET /repos​/{owner}​/{repo}​/raw​/{filepath} fails with http error 404 (or "object does not exist" in the latest gitea version) if the filepath is 40-character long.

I replicated the issue on https://try.gitea.io/danielemoroni/raw_api:
. This fails:
https://try.gitea.io/api/v1/repos/danielemoroni/raw_api/raw/filename_40char_long_xxxxxxxxxxxxxxx.txt
. This succeeds:
https://try.gitea.io/api/v1/repos/danielemoroni/raw_api/raw/filename_41char_long_xxxxxxxxxxxxxxxx.txt

The files are actually identical. I can retrieve them both without problems with another API, e.g.
https://try.gitea.io/danielemoroni/raw_api/src/branch/master/filename_40char_long_xxxxxxxxxxxxxxx.txt

Screenshots

No response

Originally created by @danielemoroni on GitHub (Sep 29, 2021). ### Gitea Version 1.12.3 ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? I deployed an official download to my server ### Database _No response_ ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Description The Gitea API GET /repos​/{owner}​/{repo}​/raw​/{filepath} fails with http error 404 (or "object does not exist" in the latest gitea version) if the filepath is 40-character long. I replicated the issue on https://try.gitea.io/danielemoroni/raw_api: . This fails: https://try.gitea.io/api/v1/repos/danielemoroni/raw_api/raw/filename_40char_long_xxxxxxxxxxxxxxx.txt . This succeeds: https://try.gitea.io/api/v1/repos/danielemoroni/raw_api/raw/filename_41char_long_xxxxxxxxxxxxxxxx.txt The files are actually identical. I can retrieve them both without problems with another API, e.g. https://try.gitea.io/danielemoroni/raw_api/src/branch/master/filename_40char_long_xxxxxxxxxxxxxxx.txt ### Screenshots _No response_
GiteaMirror added the type/bugmodifies/api labels 2025-11-02 07:41:07 -06:00
Author
Owner

@lunny commented on GitHub (Sep 29, 2021):

Could you upgrade to latest stable version?

@lunny commented on GitHub (Sep 29, 2021): Could you upgrade to latest stable version?
Author
Owner

@noerw commented on GitHub (Sep 29, 2021):

what an odd bug 👀 maybe Gitea special-cases 40 chars, because git SHAs can have that length?

edit: yup, looks like that's the case:
91e21d4fca/modules/context/api.go (L416)

@lunny they reproduced with try.gitea.io, I guess that's good enough

@noerw commented on GitHub (Sep 29, 2021): what an odd bug :eyes: maybe Gitea special-cases 40 chars, because git SHAs can have that length? edit: yup, looks like that's the case: https://github.com/go-gitea/gitea/blob/91e21d4fca8b867614d08537e92bc6c8fc7b0444/modules/context/api.go#L416 @lunny they reproduced with try.gitea.io, I guess that's good enough
Author
Owner

@noerw commented on GitHub (Sep 30, 2021):

@danielemoroni this is a stupid bug, you can work around this by prefixing your filepath with $repo_default_branch/.

However, this way to specify a ref will possibly be deprecated in 1.16, and the way you currently use this will be fixed in 1.16.0 and 1.15.4. As your Gitea version 1.12 does not receive fixes anyway, you're probably best off to update Gitea to >=1.15.4 once released, instead of adapting your API client.

@noerw commented on GitHub (Sep 30, 2021): @danielemoroni this is a stupid bug, you can work around this by prefixing your filepath with `$repo_default_branch/`. However, this way to specify a ref will possibly be deprecated in 1.16, and the way you currently use this will be fixed in 1.16.0 and 1.15.4. As your Gitea version 1.12 does not receive fixes anyway, you're probably best off to update Gitea to >=1.15.4 once released, instead of adapting your API client.
Author
Owner

@danielemoroni commented on GitHub (Sep 30, 2021):

@noerw Thank you for the explanation, and the quick response.

We tend to upgrade our gitea once a year, so we'll pick this up in our next round. I'll bear in mind the deprecation, it's not too bad to change the API calls on our side, so we might do both at the same time.

@danielemoroni commented on GitHub (Sep 30, 2021): @noerw Thank you for the explanation, and the quick response. We tend to upgrade our gitea once a year, so we'll pick this up in our next round. I'll bear in mind the deprecation, it's not too bad to change the API calls on our side, so we might do both at the same time.
Author
Owner

@lunny commented on GitHub (Oct 30, 2021):

This has been resolved by #17272 in v1.15.4 but not in 1.16.

@lunny commented on GitHub (Oct 30, 2021): This has been resolved by #17272 in v1.15.4 but not in 1.16.
Author
Owner

@yp05327 commented on GitHub (Sep 26, 2024):

This has been resolved by #17212 in v1.15.4 but not in 1.16.

There's a typo, it should be #17272.

@yp05327 commented on GitHub (Sep 26, 2024): > This has been resolved by #17212 in v1.15.4 but not in 1.16. There's a typo, it should be #17272.
Author
Owner

@yp05327 commented on GitHub (Sep 26, 2024):

And it is fixed in a special version, it is so strange.

@yp05327 commented on GitHub (Sep 26, 2024): And it is fixed in a special version, it is so strange.
Author
Owner

@lunny commented on GitHub (Sep 28, 2024):

#17185 is the original PR but not merged.

@lunny commented on GitHub (Sep 28, 2024): #17185 is the original PR but not merged.
Author
Owner

@yp05327 commented on GitHub (Sep 30, 2024):

What I want to say is that why original PR was not merged but the backport was merged first. This is so strange.

@yp05327 commented on GitHub (Sep 30, 2024): What I want to say is that why original PR was not merged but the backport was merged first. This is so strange.
Author
Owner

@wxiaoguang commented on GitHub (Nov 4, 2024):

You should use http://localhost:3000/api/v1/repos/OWNER/REPO/raw/main/filename_40char_long_xxxxxxxxxxxxxxx.txt (with a branch name or tag name) but not the ambiguous path.

@wxiaoguang commented on GitHub (Nov 4, 2024): You should use `http://localhost:3000/api/v1/repos/OWNER/REPO/raw/main/filename_40char_long_xxxxxxxxxxxxxxx.txt` (with a branch name or tag name) but not the ambiguous path.
Author
Owner

@wxiaoguang commented on GitHub (Nov 4, 2024):

And it could be fixed like this: Refactor RepoRefByType #32413

@wxiaoguang commented on GitHub (Nov 4, 2024): And it could be fixed like this: Refactor RepoRefByType #32413
Author
Owner

@wxiaoguang commented on GitHub (Nov 5, 2024):

For most use cases, this problem should have been fixed in 1.23

@wxiaoguang commented on GitHub (Nov 5, 2024): For most use cases, this problem should have been fixed in 1.23
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7907