API: repository/files GET with file_path with unescaped '.' returns non-json response
Summary
When attempting to get the contents of a repository file from the API, if the file_path parameter ends with '.txt' and the '.' is not properly escaped, the API returns:
{:file_name=>"test.txt", :file_path=>"test.txt", :size=>49, :encoding=>"base64", :content=>"VGhpcyBpcyB0ZXN0IGRhdGEKTW9yZSBkYXRhCmRhdGEKCgpkYXRhIGZvciBldmVyCg==", :ref=>"master", :blob_id=>"b94bf20fbd445f9fd7e0f080d92ddb60bb4786da", :commit_id=>"b43312f78f2480dd8444c9e99c2c810988fcd665", :last_commit_id=>"b43312f78f2480dd8444c9e99c2c810988fcd665"}
This is tested against the currently running version of gitlab on gitlab.com
Similar but not duplicate issue: gitlab-foss#31470 (closed)
Steps to reproduce
- Create a repository
- Create a file in that repository called
test.txt
(or anything ending with .txt) - Attempt to
GET
the file contents using the v4 API as documented here
Example Project
What is the current bug behavior?
API returns invalid data for incorrectly escaped paths
What is the expected correct behavior?
That the API returns valid JSON or no response in every case
Relevant logs and/or screenshots
$ curl --request GET --header 'PRIVATE-TOKEN: <token-here>' 'https://gitlab.com/api/v4/projects/3684663/repository/files/test.txt?ref=master'
{:file_name=>"test.txt", :file_path=>"test.txt", :size=>49, :encoding=>"base64", :content=>"VGhpcyBpcyB0ZXN0IGRhdGEKTW9yZSBkYXRhCmRhdGEKCgpkYXRhIGZvciBldmVyCg==", :ref=>"master", :blob_id=>"b94bf20fbd445f9fd7e0f080d92ddb60bb4786da", :commit_id=>"b43312f78f2480dd8444c9e99c2c810988fcd665", :last_commit_id=>"b43312f78f2480dd8444c9e99c2c810988fcd665"}
Output of checks
This bug happens on GitLab.com
Possible fixes
Unknown