diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-08-15 20:01:48 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-08-15 20:01:48 +0300 |
commit | 05151f7699ee2adf67ce835413dfdbd80c58a3e5 (patch) | |
tree | 923f09ad89e18fae2101484931dd2c8d10478c66 | |
parent | 97b768508c360d2ae767a559b5037fe464061440 (diff) | |
parent | b7e98620046501144302ff8f9fbf22ff03ef4db7 (diff) |
Merge branch 'issue_31790' into 'master'
Fix API responses when dealing with txt files
Closes #31790
See merge request !13474
-rw-r--r-- | changelogs/unreleased/issue_31790.yml | 4 | ||||
-rw-r--r-- | lib/api/files.rb | 3 | ||||
-rw-r--r-- | spec/requests/api/files_spec.rb | 10 |
3 files changed, 17 insertions, 0 deletions
diff --git a/changelogs/unreleased/issue_31790.yml b/changelogs/unreleased/issue_31790.yml new file mode 100644 index 00000000000..df02cad423a --- /dev/null +++ b/changelogs/unreleased/issue_31790.yml @@ -0,0 +1,4 @@ +--- +title: Fix API responses when dealing with txt files +merge_request: +author: diff --git a/lib/api/files.rb b/lib/api/files.rb index 450334fee84..e2ac7142bc4 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -1,5 +1,8 @@ module API class Files < Grape::API + # Prevents returning plain/text responses for files with .txt extension + after_validation { content_type "application/json" } + helpers do def commit_params(attrs) { diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 55c998b13b8..ea97c556430 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -33,6 +33,15 @@ describe API::Files do expect(Base64.decode64(json_response['content']).lines.first).to eq("require 'fileutils'\n") end + it 'returns json when file has txt extension' do + file_path = "bar%2Fbranch-test.txt" + + get api(route(file_path), current_user), params + + expect(response).to have_http_status(200) + expect(response.content_type).to eq('application/json') + end + it 'returns file by commit sha' do # This file is deleted on HEAD file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" @@ -220,6 +229,7 @@ describe API::Files do post api(route("new_file_with_author%2Etxt"), user), valid_params expect(response).to have_http_status(201) + expect(response.content_type).to eq('application/json') last_commit = project.repository.commit.raw expect(last_commit.author_email).to eq(author_email) expect(last_commit.author_name).to eq(author_name) |