Commit 39c7cae9 authored by Daniel Stone's avatar Daniel Stone

Fix API requests for branch names ending in .txt

Similar to gitlab-foss!13174 for files, Grape would try to return a
text result when the branch name ended in '.txt'. Fix this by forcing it
to always return JSON results for branches, no matter what the name.

Fixes: #217097
parent ff5ef5c6
---
title: Fix API requests for branch names ending in .txt
merge_request: 31446
author: Daniel Stone
type: fixed
......@@ -8,6 +8,8 @@ module API
BRANCH_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(branch: API::NO_SLASH_URL_PART_REGEX)
after_validation { content_type "application/json" }
before do
require_repository_enabled!
authorize! :download_code, user_project
......
......@@ -16,6 +16,7 @@ describe API::Branches do
before do
project.add_maintainer(user)
project.repository.add_branch(user, 'ends-with.txt', branch_sha)
end
describe "GET /projects/:id/repository/branches" do
......@@ -240,6 +241,12 @@ describe API::Branches do
it_behaves_like 'repository branch'
end
context 'when branch contains dot txt' do
let(:branch_name) { project.repository.find_branch('ends-with.txt').name }
it_behaves_like 'repository branch'
end
context 'when branch contains a slash' do
let(:branch_name) { branch_with_slash.name }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment