summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-12-13 13:19:28 +0000
committerRémy Coutable <remy@rymai.me>2016-12-13 13:19:28 +0000
commit0764c2ead1cc3ee3778a24218412317ba19b5e83 (patch)
tree36fdc74eb42e635f4124d33ae5d68fa25ec9bad0
parent8f299a5825997eb279011d67565689d506bf7d66 (diff)
parent61aa90ef2089c9d840b88f14a553ef0dd49b779f (diff)
downloadgitlab-ce-0764c2ead1cc3ee3778a24218412317ba19b5e83.tar.gz
Merge branch 'allow-more-filenames' into 'master'
Allow all alphanumeric characters in file names ## What does this MR do? Allow more characters in file names such as Chinese symbols. ## Why was this MR needed? It is annoying that some files which can be uploaded using Git CLI cannot be created with the web editor. ## What are the relevant issue numbers? fixes #20190 See merge request !8002
-rw-r--r--changelogs/unreleased/allow-more-filenames.yml4
-rw-r--r--lib/gitlab/regex.rb4
-rw-r--r--spec/features/projects/files/creating_a_file_spec.rb44
3 files changed, 50 insertions, 2 deletions
diff --git a/changelogs/unreleased/allow-more-filenames.yml b/changelogs/unreleased/allow-more-filenames.yml
new file mode 100644
index 00000000000..7989f94e528
--- /dev/null
+++ b/changelogs/unreleased/allow-more-filenames.yml
@@ -0,0 +1,4 @@
+---
+title: Allow all alphanumeric characters in file names
+merge_request: 8002
+author: winniehell
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index a06cf6a989c..d9d1e3cccca 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -61,7 +61,7 @@ module Gitlab
end
def file_name_regex
- @file_name_regex ||= /\A[a-zA-Z0-9_\-\.\@]*\z/.freeze
+ @file_name_regex ||= /\A[[[:alnum:]]_\-\.\@]*\z/.freeze
end
def file_name_regex_message
@@ -69,7 +69,7 @@ module Gitlab
end
def file_path_regex
- @file_path_regex ||= /\A[a-zA-Z0-9_\-\.\/\@]*\z/.freeze
+ @file_path_regex ||= /\A[[[:alnum:]]_\-\.\/\@]*\z/.freeze
end
def file_path_regex_message
diff --git a/spec/features/projects/files/creating_a_file_spec.rb b/spec/features/projects/files/creating_a_file_spec.rb
new file mode 100644
index 00000000000..ae448706130
--- /dev/null
+++ b/spec/features/projects/files/creating_a_file_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+feature 'User wants to create a file', feature: true do
+ include WaitForAjax
+
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ background do
+ project.team << [user, :master]
+ login_as user
+ visit namespace_project_new_blob_path(project.namespace, project, project.default_branch)
+ end
+
+ def submit_new_file(options)
+ file_name = find('#file_name')
+ file_name.set options[:file_name] || 'README.md'
+
+ file_content = find('#file-content')
+ file_content.set options[:file_content] || 'Some content'
+
+ click_button 'Commit Changes'
+ end
+
+ scenario 'file name contains Chinese characters' do
+ submit_new_file(file_name: '测试.md')
+ expect(page).to have_content 'The file has been successfully created.'
+ end
+
+ scenario 'directory name contains Chinese characters' do
+ submit_new_file(file_name: '中文/测试.md')
+ expect(page).to have_content 'The file has been successfully created.'
+ end
+
+ scenario 'file name contains invalid characters' do
+ submit_new_file(file_name: '\\')
+ expect(page).to have_content 'Your changes could not be committed, because the file name can contain only'
+ end
+
+ scenario 'file name contains directory traversal' do
+ submit_new_file(file_name: '../README.md')
+ expect(page).to have_content 'Your changes could not be committed, because the file name cannot include directory traversal.'
+ end
+end