Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
danielemoroni opened this issue Sep 29, 2021 · 12 comments
Labels
modifies/api This PR adds API routes or modifies them type/bug

Comments

@danielemoroni
Copy link

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

@lunny
Copy link
Member

lunny commented Sep 29, 2021

Could you upgrade to latest stable version?

@noerw
Copy link
Member

noerw commented 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:

} else if len(refName) == 40 {

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

@noerw noerw added modifies/api This PR adds API routes or modifies them type/bug labels Sep 29, 2021
@noerw noerw added this to the 1.15.4 milestone Sep 29, 2021
noerw added a commit to noerw/gitea that referenced this issue Sep 29, 2021
we just deprecated this API, but this is a short fix to go-gitea#17179
A more minimal fix would be to check
  if len(parts) > 1
in line context/repo.go#L698
@noerw
Copy link
Member

noerw commented 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.

@danielemoroni
Copy link
Author

@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.

noerw added a commit to noerw/gitea that referenced this issue Oct 8, 2021
...when path contains no hash-path-separator ('/')

This is a workaround to go-gitea#17179.

Entering this case when `path` does not contain a '/' does not really
make sense, as that means the tree path is empty, but this case is only
entered for routes that expect a non-empty tree path.

Treepaths like <40-char-dirname>/<filename> will still fail,
but hopefully don't occur that often. A more complete fix that avoids
this case too is outlined in go-gitea#17185, but too big of a change to backport
techknowlogick pushed a commit that referenced this issue Oct 8, 2021
...when path contains no hash-path-separator ('/')

This is a workaround to #17179.

Entering this case when `path` does not contain a '/' does not really
make sense, as that means the tree path is empty, but this case is only
entered for routes that expect a non-empty tree path.

Treepaths like <40-char-dirname>/<filename> will still fail,
but hopefully don't occur that often. A more complete fix that avoids
this case too is outlined in #17185, but too big of a change to backport
@techknowlogick techknowlogick modified the milestones: 1.15.4, 1.15.5 Oct 8, 2021
@6543 6543 modified the milestones: 1.15.5, 1.15.6 Oct 20, 2021
@lunny lunny modified the milestones: 1.15.6, 1.15.7 Oct 28, 2021
@lunny
Copy link
Member

lunny commented Oct 30, 2021

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

@lunny lunny added this to the 1.16.0 milestone Oct 30, 2021
@lunny lunny added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Oct 30, 2021
@techknowlogick techknowlogick modified the milestones: 1.16.0, 1.17.0 Nov 23, 2021
@wxiaoguang wxiaoguang removed the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Jun 8, 2022
@wxiaoguang wxiaoguang removed this from the 1.17.0 milestone Jun 8, 2022
@yp05327
Copy link
Contributor

yp05327 commented 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
Copy link
Contributor

yp05327 commented Sep 26, 2024

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

@lunny
Copy link
Member

lunny commented Sep 28, 2024

#17185 is the original PR but not merged.

@yp05327
Copy link
Contributor

yp05327 commented 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.

lunny pushed a commit to lunny/gitea that referenced this issue Oct 24, 2024
...when path contains no hash-path-separator ('/')

This is a workaround to go-gitea#17179.

Entering this case when `path` does not contain a '/' does not really
make sense, as that means the tree path is empty, but this case is only
entered for routes that expect a non-empty tree path.

Treepaths like <40-char-dirname>/<filename> will still fail,
but hopefully don't occur that often. A more complete fix that avoids
this case too is outlined in go-gitea#17185, but too big of a change to backport
@wxiaoguang
Copy link
Contributor

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
Copy link
Contributor

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

@wxiaoguang
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modifies/api This PR adds API routes or modifies them type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants