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
Jérome Perrin
gitlab-ce
Commits
f3b6c552
Commit
f3b6c552
authored
Aug 21, 2017
by
Marc Siegfriedt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix :file_path - add requirements:
parent
d540d43e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
6 deletions
+22
-6
changelogs/unreleased/31470-fix-api-files-raw.yml
changelogs/unreleased/31470-fix-api-files-raw.yml
+5
-0
lib/api/files.rb
lib/api/files.rb
+8
-6
spec/requests/api/files_spec.rb
spec/requests/api/files_spec.rb
+9
-0
No files found.
changelogs/unreleased/31470-fix-api-files-raw.yml
0 → 100644
View file @
f3b6c552
---
title
:
Fix the /projects/:id/repository/files/:file_path/raw endpoint to handle dots in the file_path
merge_request
:
13512
author
:
mahcsig
type
:
fixed
lib/api/files.rb
View file @
f3b6c552
module
API
class
Files
<
Grape
::
API
FILE_ENDPOINT_REQUIREMENTS
=
API
::
PROJECT_ENDPOINT_REQUIREMENTS
.
merge
(
file_path:
API
::
NO_SLASH_URL_PART_REGEX
)
# Prevents returning plain/text responses for files with .txt extension
after_validation
{
content_type
"application/json"
}
...
...
@@ -58,13 +60,13 @@ module API
params
do
requires
:id
,
type:
String
,
desc:
'The project ID'
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
desc
'Get raw file contents from the repository'
params
do
requires
:file_path
,
type:
String
,
desc:
'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires
:ref
,
type:
String
,
desc:
'The name of branch, tag commit'
end
get
":id/repository/files/:file_path/raw"
do
get
":id/repository/files/:file_path/raw"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
assign_file_vars!
send_git_blob
@repo
,
@blob
...
...
@@ -75,7 +77,7 @@ module API
requires
:file_path
,
type:
String
,
desc:
'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires
:ref
,
type:
String
,
desc:
'The name of branch, tag or commit'
end
get
":id/repository/files/:file_path"
,
requirements:
{
file_path:
/.+/
}
do
get
":id/repository/files/:file_path"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
assign_file_vars!
{
...
...
@@ -95,7 +97,7 @@ module API
params
do
use
:extended_file_params
end
post
":id/repository/files/:file_path"
,
requirements:
{
file_path:
/.+/
}
do
post
":id/repository/files/:file_path"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
authorize!
:push_code
,
user_project
file_params
=
declared_params
(
include_missing:
false
)
...
...
@@ -113,7 +115,7 @@ module API
params
do
use
:extended_file_params
end
put
":id/repository/files/:file_path"
,
requirements:
{
file_path:
/.+/
}
do
put
":id/repository/files/:file_path"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
authorize!
:push_code
,
user_project
file_params
=
declared_params
(
include_missing:
false
)
...
...
@@ -137,7 +139,7 @@ module API
params
do
use
:simple_file_params
end
delete
":id/repository/files/:file_path"
,
requirements:
{
file_path:
/.+/
}
do
delete
":id/repository/files/:file_path"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
authorize!
:push_code
,
user_project
file_params
=
declared_params
(
include_missing:
false
)
...
...
spec/requests/api/files_spec.rb
View file @
f3b6c552
...
...
@@ -125,6 +125,15 @@ describe API::Files do
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns raw file info for files with dots'
do
url
=
route
(
'.gitignore'
)
+
"/raw"
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_blob
)
get
api
(
url
,
current_user
),
params
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns file by commit sha'
do
# This file is deleted on HEAD
file_path
=
"files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
...
...
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