Skip to content

API: branch names need special handling when containing a / #2088

@stephenc

Description

@stephenc
  • Gitea version (or commit ref): 8fd43f2 (likely all versions prio)
  • Git version: N/A
  • Operating system: N/A
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
    • N/A
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

The API URL scheme does not take into account potentially URL unsafe characters that could be part of the naming scheme.

For example, in this repo: https://try.gitea.io/stephenc/branch-with-slash I have created a branch with a slash in the name: https://try.gitea.io/stephenc/branch-with-slash/src/feature/1

Now browsing the web UI does not seem to have issues with the slash: https://try.gitea.io/stephenc/branch-with-slash/src/feature/1/ABOUT.md

Nor does accessing the raw URL on the API:

https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/raw/feature/1/ABOUT.md

But we cannot retrieve a single branch by name, e.g.

https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/branches lists all branches

https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/branches/master gets just the master branch...

but

https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/branches/feature/1 is 404

https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/branches/feature%2F1 is 404

The good news is that git does not allow you to simultaneously create both refs/heads/feature and refs/heads/feature/1 so currently you should not have to differentiate between whether https://try.gitea.io/api/v1/repos/stephenc/branch-with-slash/raw/feature/1/ABOUT.md is looking for the ABOUT.md file in the feature/1 branch or the 1/ABOUT.md file in the feature branch... but perhaps you may

By way of comparison, GitHub uses the / as is, so https://api.github.com/repos/cloudbeers/demo-2017-03/branches/feature/1 works

I have not tested other URL unsafe characters that are valid in a git branch name, so you may also need to add those to your test scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions