Skip to content

Branch Protection API {name} parameter cannot parse branch rule names with "/" inside. #35160

@ksjdragon

Description

@ksjdragon

Description

If a branch protection rule was created with "/", it is not possible to access it with the API, with any of the following:

GET /repos/{owner}/{repo}/branch_protections/{name}
DELETE /repos/{owner}/{repo}/branch_protections/{name}
PATCH /repos/{owner}/{repo}/branch_protections/{name}

You will obtain a 404 error. After looking through the code, the reason seems to be how
the chi router handles parameters. It does not greedily match the rest of the URL, and
will match up to the next /.

My proposed solution is to change the API let the rule_name simply be in the body of the JSON sent.

However, if that's not desired, I noticed that URI-encoding the "/" into "%2F", seems work because ctx.PathParam does unescaping. This is not mentioned anywhere in the docs (to my knowledge),
so in that case, I believe it should be written in the API guide.

Gitea Version

1.24.2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.47.1

Operating System

CentOS Stream 10

How are you running Gitea?

Docker Container

Database

PostgreSQL

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions