Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b7e98620
Commit
b7e98620
authored
Aug 10, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix API responses when dealing with txt files
parent
fe09c25d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
changelogs/unreleased/issue_31790.yml
changelogs/unreleased/issue_31790.yml
+4
-0
lib/api/files.rb
lib/api/files.rb
+3
-0
spec/requests/api/files_spec.rb
spec/requests/api/files_spec.rb
+10
-0
No files found.
changelogs/unreleased/issue_31790.yml
0 → 100644
View file @
b7e98620
---
title
:
Fix API responses when dealing with txt files
merge_request
:
author
:
lib/api/files.rb
View file @
b7e98620
module
API
module
API
class
Files
<
Grape
::
API
class
Files
<
Grape
::
API
# Prevents returning plain/text responses for files with .txt extension
after_validation
{
content_type
"application/json"
}
helpers
do
helpers
do
def
commit_params
(
attrs
)
def
commit_params
(
attrs
)
{
{
...
...
spec/requests/api/files_spec.rb
View file @
b7e98620
...
@@ -33,6 +33,15 @@ describe API::Files do
...
@@ -33,6 +33,15 @@ describe API::Files do
expect
(
Base64
.
decode64
(
json_response
[
'content'
]).
lines
.
first
).
to
eq
(
"require 'fileutils'
\n
"
)
expect
(
Base64
.
decode64
(
json_response
[
'content'
]).
lines
.
first
).
to
eq
(
"require 'fileutils'
\n
"
)
end
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
it
'returns file by commit sha'
do
# This file is deleted on HEAD
# This file is deleted on HEAD
file_path
=
"files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
file_path
=
"files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
...
@@ -220,6 +229,7 @@ describe API::Files do
...
@@ -220,6 +229,7 @@ describe API::Files do
post
api
(
route
(
"new_file_with_author%2Etxt"
),
user
),
valid_params
post
api
(
route
(
"new_file_with_author%2Etxt"
),
user
),
valid_params
expect
(
response
).
to
have_http_status
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
response
.
content_type
).
to
eq
(
'application/json'
)
last_commit
=
project
.
repository
.
commit
.
raw
last_commit
=
project
.
repository
.
commit
.
raw
expect
(
last_commit
.
author_email
).
to
eq
(
author_email
)
expect
(
last_commit
.
author_email
).
to
eq
(
author_email
)
expect
(
last_commit
.
author_name
).
to
eq
(
author_name
)
expect
(
last_commit
.
author_name
).
to
eq
(
author_name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment