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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
76b0518f
Commit
76b0518f
authored
Jun 21, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use #filename when generating upload URLs
We don't need to find the filename from the remote URL
parent
fb35a3b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
28 deletions
+43
-28
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+1
-1
app/uploaders/personal_file_uploader.rb
app/uploaders/personal_file_uploader.rb
+1
-1
changelogs/unreleased/53357-fix-plus-in-upload-file-names.yml
...gelogs/unreleased/53357-fix-plus-in-upload-file-names.yml
+5
-0
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+36
-26
No files found.
app/uploaders/file_uploader.rb
View file @
76b0518f
...
@@ -203,6 +203,6 @@ class FileUploader < GitlabUploader
...
@@ -203,6 +203,6 @@ class FileUploader < GitlabUploader
end
end
def
secure_url
def
secure_url
File
.
join
(
'/uploads'
,
@secret
,
file
.
file
name
)
File
.
join
(
'/uploads'
,
@secret
,
filename
)
end
end
end
end
app/uploaders/personal_file_uploader.rb
View file @
76b0518f
...
@@ -93,6 +93,6 @@ class PersonalFileUploader < FileUploader
...
@@ -93,6 +93,6 @@ class PersonalFileUploader < FileUploader
end
end
def
secure_url
def
secure_url
File
.
join
(
'/'
,
base_dir
,
secret
,
file
.
file
name
)
File
.
join
(
'/'
,
base_dir
,
secret
,
filename
)
end
end
end
end
changelogs/unreleased/53357-fix-plus-in-upload-file-names.yml
0 → 100644
View file @
76b0518f
---
title
:
Fix broken URLs for uploads with a plus in the filename
merge_request
:
29915
author
:
type
:
fixed
spec/uploaders/file_uploader_spec.rb
View file @
76b0518f
...
@@ -184,40 +184,37 @@ describe FileUploader do
...
@@ -184,40 +184,37 @@ describe FileUploader do
end
end
end
end
describe
'#cache!'
do
context
'when remote file is used'
do
subject
do
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
)
}
uploader
.
store!
(
uploaded_file
)
end
context
'when remote file is used'
do
let!
(
:fog_connection
)
do
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
)
}
stub_uploads_object_storage
(
described_class
)
end
let!
(
:fog_connection
)
do
let
(
:filename
)
{
"my file.txt"
}
stub_uploads_object_storage
(
described_class
)
let
(
:uploaded_file
)
do
end
UploadedFile
.
new
(
temp_file
.
path
,
filename:
filename
,
remote_id:
"test/123123"
)
end
let
(
:uploaded_file
)
do
let!
(
:fog_file
)
do
UploadedFile
.
new
(
temp_file
.
path
,
filename:
"my file.txt"
,
remote_id:
"test/123123"
)
fog_connection
.
directories
.
new
(
key:
'uploads'
).
files
.
create
(
end
key:
'tmp/uploads/test/123123'
,
body:
'content'
)
end
let!
(
:fog_file
)
do
before
do
fog_connection
.
directories
.
new
(
key:
'uploads'
).
files
.
create
(
FileUtils
.
touch
(
temp_file
)
key:
'tmp/uploads/test/123123'
,
body:
'content'
)
end
before
do
uploader
.
store!
(
uploaded_file
)
FileUtils
.
touch
(
temp_file
)
end
end
after
do
after
do
FileUtils
.
rm_f
(
temp_file
)
FileUtils
.
rm_f
(
temp_file
)
end
end
describe
'#cache!'
do
it
'file is stored remotely in permament location with sanitized name'
do
it
'file is stored remotely in permament location with sanitized name'
do
subject
expect
(
uploader
).
to
be_exists
expect
(
uploader
).
to
be_exists
expect
(
uploader
).
not_to
be_cached
expect
(
uploader
).
not_to
be_cached
expect
(
uploader
).
not_to
be_file_storage
expect
(
uploader
).
not_to
be_file_storage
...
@@ -228,5 +225,18 @@ describe FileUploader do
...
@@ -228,5 +225,18 @@ describe FileUploader do
expect
(
uploader
.
object_store
).
to
eq
(
described_class
::
Store
::
REMOTE
)
expect
(
uploader
.
object_store
).
to
eq
(
described_class
::
Store
::
REMOTE
)
end
end
end
end
describe
'#to_h'
do
subject
{
uploader
.
to_h
}
let
(
:filename
)
{
'my+file.txt'
}
it
'generates URL using original file name instead of filename returned by object storage'
do
# GCS returns a URL with a `+` instead of `%2B`
allow
(
uploader
.
file
).
to
receive
(
:url
).
and_return
(
'https://storage.googleapis.com/gitlab-test-uploads/@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b/64c5065e62100b1a12841644256a98be/my+file.txt'
)
expect
(
subject
[
:url
]).
to
end_with
(
filename
)
end
end
end
end
end
end
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