Skip to content

Both repository/contents API endpoints return 500 when a file contains a '%' sign #22843

@SolarBear

Description

@SolarBear

Description

This bug can be found in both GET endpoints: repository/contents as well as repository/contents/{filepath}

One can reproduce this bug fairly easily:

  1. Create a new repository. I called mine testpct.
  2. Clone the empty repository locally.
  3. Add a file whose name contains a '%' sign (e.g. hello%mother.txt)
  4. Add, commit and push this file.
  5. Using the Swagger interface or some other REST client, make a GET API call to http://MYHOST/api/v1/repos/USERNAME/testpct/contents
  6. This results in a 500 error whose body is simply
{
  "message": "",
  "url": "http://localhost:3000/api/swagger"
}
  1. Back to your filesystem, create a folder called folder.
  2. Move the the file you've created into that subfolder.
  3. Make a GET call to http://MYHOST/api/v1/repos/USERNAME/testpct/contents/folder
  4. This results in the same error as the previous one.

For the record, I am well aware that having special characters in file names is bad and, no, changing these file names is not possible. :)

Gitea Version

1.17.0, 1.18.3

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

https://gist.github.com/SolarBear/66fe09b5817c1aab74fa5292bebc894d

Screenshots

No response

Git Version

No response

Operating System

Windows 10

How are you running Gitea?

Database

SQLite

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions