summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2018-07-18 14:21:32 +0000
committerKamil TrzciƄski <ayufan@ayufan.eu>2018-07-18 14:21:32 +0000
commitbc999d53201c31b133971b0b1a6c32bf66807035 (patch)
tree47155e9db3ae4b4e20c5c0196eb3fc579b18c43e /lib
parent29477fc2d81f9075508df3a7633e1efa63b7a0f8 (diff)
downloadgitlab-ce-bc999d53201c31b133971b0b1a6c32bf66807035.tar.gz
Fix filename for accelerated uploads
Diffstat (limited to 'lib')
-rw-r--r--lib/uploaded_file.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/uploaded_file.rb b/lib/uploaded_file.rb
index 4b9cb59eab5..53e5ac02e42 100644
--- a/lib/uploaded_file.rb
+++ b/lib/uploaded_file.rb
@@ -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