Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-09-07 17:10:15 +0300
committerDouwe Maan <douwe@gitlab.com>2018-09-07 17:10:15 +0300
commitf67211f9885df6ebbf68c7a9b0106618fa40ff2f (patch)
treee766521bd1f124300692a303e10a9f04c35c85ba /app/services/wikis
parent7f2b287f6622dd5052da369a8e83fd6707d96173 (diff)
Replace whitespaces in wiki page attachments file names
Diffstat (limited to 'app/services/wikis')
-rw-r--r--app/services/wikis/create_attachment_service.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/services/wikis/create_attachment_service.rb b/app/services/wikis/create_attachment_service.rb
index 30fe0e371a6..df31ad7c8ea 100644
--- a/app/services/wikis/create_attachment_service.rb
+++ b/app/services/wikis/create_attachment_service.rb
@@ -11,7 +11,7 @@ module Wikis
def initialize(*args)
super
- @file_name = truncate_file_name(params[:file_name])
+ @file_name = clean_file_name(params[:file_name])
@file_path = File.join(ATTACHMENT_PATH, SecureRandom.hex, @file_name) if @file_name
@commit_message ||= "Upload attachment #{@file_name}"
@branch_name ||= wiki.default_branch
@@ -23,8 +23,16 @@ module Wikis
private
- def truncate_file_name(file_name)
+ def clean_file_name(file_name)
return unless file_name.present?
+
+ file_name = truncate_file_name(file_name)
+ # CommonMark does not allow Urls with whitespaces, so we have to replace them
+ # Using the same regex Carrierwave use to replace invalid characters
+ file_name.gsub(CarrierWave::SanitizedFile.sanitize_regexp, '_')
+ end
+
+ def truncate_file_name(file_name)
return file_name if file_name.length <= MAX_FILENAME_LENGTH
extension = File.extname(file_name)