Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
bc999d53
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bc999d53
编写于
7月 18, 2018
作者:
J
Jan Provaznik
提交者:
Kamil Trzciński
7月 18, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix filename for accelerated uploads
上级
29477fc2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
86 addition
and
18 deletion
+86
-18
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+0
-4
changelogs/unreleased/fix-filename-for-direct-uploads.yml
changelogs/unreleased/fix-filename-for-direct-uploads.yml
+5
-0
lib/uploaded_file.rb
lib/uploaded_file.rb
+11
-1
spec/lib/uploaded_file_spec.rb
spec/lib/uploaded_file_spec.rb
+24
-13
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+46
-0
未找到文件。
app/uploaders/file_uploader.rb
浏览文件 @
bc999d53
...
...
@@ -136,10 +136,6 @@ class FileUploader < GitlabUploader
}
end
def
filename
self
.
file
.
filename
end
def
upload
=
(
value
)
super
...
...
changelogs/unreleased/fix-filename-for-direct-uploads.yml
0 → 100644
浏览文件 @
bc999d53
---
title
:
Fix filename for accelerated uploads
merge_request
:
author
:
type
:
fixed
lib/uploaded_file.rb
浏览文件 @
bc999d53
...
...
@@ -21,7 +21,7 @@ class UploadedFile
raise
InvalidPathError
,
"
#{
path
}
file does not exist"
unless
::
File
.
exist?
(
path
)
@content_type
=
content_type
@original_filename
=
filename
||
::
File
.
basename
(
path
)
@original_filename
=
sanitize_filename
(
filename
||
path
)
@content_type
=
content_type
@sha256
=
sha256
@remote_id
=
remote_id
...
...
@@ -55,6 +55,16 @@ class UploadedFile
end
end
# copy-pasted from CarrierWave::SanitizedFile
def
sanitize_filename
(
name
)
name
=
name
.
tr
(
"
\\
"
,
"/"
)
# work-around for IE
name
=
::
File
.
basename
(
name
)
name
=
name
.
gsub
(
CarrierWave
::
SanitizedFile
.
sanitize_regexp
,
"_"
)
name
=
"_
#{
name
}
"
if
name
=~
/\A\.+\z/
name
=
"unnamed"
if
name
.
empty?
name
.
mb_chars
.
to_s
end
def
path
@tempfile
.
path
end
...
...
spec/lib/uploaded_file_spec.rb
浏览文件 @
bc999d53
require
'spec_helper'
describe
UploadedFile
do
describe
".from_params"
do
let
(
:temp_dir
)
{
Dir
.
tmpdir
}
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
,
temp_dir
)
}
let
(
:upload_path
)
{
nil
}
let
(
:temp_dir
)
{
Dir
.
tmpdir
}
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
,
temp_dir
)
}
subject
do
described_class
.
from_params
(
params
,
:file
,
upload_path
)
end
before
do
FileUtils
.
touch
(
temp_file
)
end
before
do
FileUtils
.
touch
(
temp_file
)
end
after
do
FileUtils
.
rm_f
(
temp_file
)
end
describe
".from_params"
do
let
(
:upload_path
)
{
nil
}
after
do
FileUtils
.
rm_f
(
temp_file
)
FileUtils
.
rm_r
(
upload_path
)
if
upload_path
end
subject
do
described_class
.
from_params
(
params
,
:file
,
upload_path
)
end
context
'when valid file is specified'
do
context
'only local path is specified'
do
let
(
:params
)
do
...
...
@@ -37,7 +41,7 @@ describe UploadedFile do
context
'all parameters are specified'
do
let
(
:params
)
do
{
'file.path'
=>
temp_file
.
path
,
'file.name'
=>
'
my_file
.txt'
,
'file.name'
=>
'
dir/my file&
.txt'
,
'file.type'
=>
'my/type'
,
'file.sha256'
=>
'sha256'
,
'file.remote_id'
=>
'remote_id'
}
...
...
@@ -48,7 +52,7 @@ describe UploadedFile do
end
it
"generates filename from path"
do
expect
(
subject
.
original_filename
).
to
eq
(
'my_file.txt'
)
expect
(
subject
.
original_filename
).
to
eq
(
'my_file
_
.txt'
)
expect
(
subject
.
content_type
).
to
eq
(
'my/type'
)
expect
(
subject
.
sha256
).
to
eq
(
'sha256'
)
expect
(
subject
.
remote_id
).
to
eq
(
'remote_id'
)
...
...
@@ -113,4 +117,11 @@ describe UploadedFile do
end
end
end
describe
'#sanitize_filename'
do
it
{
expect
(
described_class
.
new
(
temp_file
.
path
).
sanitize_filename
(
'spaced name'
)).
to
eq
(
'spaced_name'
)
}
it
{
expect
(
described_class
.
new
(
temp_file
.
path
).
sanitize_filename
(
'#$%^&'
)).
to
eq
(
'_____'
)
}
it
{
expect
(
described_class
.
new
(
temp_file
.
path
).
sanitize_filename
(
'..'
)).
to
eq
(
'_..'
)
}
it
{
expect
(
described_class
.
new
(
temp_file
.
path
).
sanitize_filename
(
''
)).
to
eq
(
'unnamed'
)
}
end
end
spec/uploaders/file_uploader_spec.rb
浏览文件 @
bc999d53
...
...
@@ -166,4 +166,50 @@ describe FileUploader do
uploader
.
upload
=
upload
end
end
describe
'#cache!'
do
subject
do
uploader
.
store!
(
uploaded_file
)
end
context
'when remote file is used'
do
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
)
}
let!
(
:fog_connection
)
do
stub_uploads_object_storage
(
described_class
)
end
let
(
:uploaded_file
)
do
UploadedFile
.
new
(
temp_file
.
path
,
filename:
"my file.txt"
,
remote_id:
"test/123123"
)
end
let!
(
:fog_file
)
do
fog_connection
.
directories
.
get
(
'uploads'
).
files
.
create
(
key:
'tmp/uploads/test/123123'
,
body:
'content'
)
end
before
do
FileUtils
.
touch
(
temp_file
)
end
after
do
FileUtils
.
rm_f
(
temp_file
)
end
it
'file is stored remotely in permament location with sanitized name'
do
subject
expect
(
uploader
).
to
be_exists
expect
(
uploader
).
not_to
be_cached
expect
(
uploader
).
not_to
be_file_storage
expect
(
uploader
.
path
).
not_to
be_nil
expect
(
uploader
.
path
).
not_to
include
(
'tmp/upload'
)
expect
(
uploader
.
path
).
not_to
include
(
'tmp/cache'
)
expect
(
uploader
.
url
).
to
include
(
'/my_file.txt'
)
expect
(
uploader
.
object_store
).
to
eq
(
described_class
::
Store
::
REMOTE
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录