diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-07-03 13:55:43 +0100 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-07-05 16:08:57 +0100 |
commit | d1e0b1b3a8404f3a7b54db09c46fb614ca3fcb93 (patch) | |
tree | 6966390483970e4aa0ef5d5da572769ea84817bf | |
parent | 81dba76b9d7d120cd22e3619a4058bd4885be9bc (diff) | |
download | gitlab-ce-d1e0b1b3a8404f3a7b54db09c46fb614ca3fcb93.tar.gz |
Allow creation of files and directories with spaces in web UI
-rw-r--r-- | changelogs/unreleased/23162-allow-creation-of-files-and-dirs-with-spaces-in-web-ui.yml | 4 | ||||
-rw-r--r-- | features/steps/project/source/browse_files.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/regex.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/git/index_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 10 |
5 files changed, 35 insertions, 2 deletions
diff --git a/changelogs/unreleased/23162-allow-creation-of-files-and-dirs-with-spaces-in-web-ui.yml b/changelogs/unreleased/23162-allow-creation-of-files-and-dirs-with-spaces-in-web-ui.yml new file mode 100644 index 00000000000..442406c3c04 --- /dev/null +++ b/changelogs/unreleased/23162-allow-creation-of-files-and-dirs-with-spaces-in-web-ui.yml @@ -0,0 +1,4 @@ +--- +title: Allow creation of files and directories with spaces through Web UI +merge_request: 12608 +author: diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index 02434319a08..45c47b1a575 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -93,7 +93,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps end step 'I fill the new file name with an illegal name' do - fill_in :file_name, with: 'Spaces Not Allowed' + fill_in :file_name, with: 'Filename/Slash' end step 'I fill the new file name with a new directory' do diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index b706434217d..a5bd2175921 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -20,7 +20,7 @@ module Gitlab end def file_name_regex - @file_name_regex ||= /\A[[[:alnum:]]_\-\.\@\+]*\z/.freeze + @file_name_regex ||= /\A[^\/\0]*\z/.freeze end def file_name_regex_message diff --git a/spec/lib/gitlab/git/index_spec.rb b/spec/lib/gitlab/git/index_spec.rb index 21b71654251..8d63f81e4fd 100644 --- a/spec/lib/gitlab/git/index_spec.rb +++ b/spec/lib/gitlab/git/index_spec.rb @@ -25,6 +25,16 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) end + + it 'creates the file if file_path has spaces in between words' do + options[:file_path] = 'new file.txt' + + index.create(options) + entry = index.get(options[:file_path]) + + expect(entry).not_to be_nil + expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) + end end context 'when a file at that path exists' do @@ -81,6 +91,15 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil end + + it 'creates the dir if it has spaces in between words' do + options[:file_path] = 'new dir' + + index.create_dir(options) + entry = index.get(options[:file_path] + '/.gitkeep') + + expect(entry).not_to be_nil + end end context 'when a file at that path exists' do diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index c69f0a495db..80b363355da 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -347,6 +347,16 @@ describe Repository, models: true do expect(blob.data).to eq('Changelog!') end + it 'creates new file with spaces in between successfully' do + expect do + repository.create_file(user, 'NEW FILE', 'File!', + message: 'Create NEW FILE', + branch_name: 'master') + end.to change { repository.commits('master').count }.by(1) + + expect(repository.blob_at('master', 'NEW FILE').data).to eq('File!') + end + it 'respects the autocrlf setting' do repository.create_file(user, 'hello.txt', "Hello,\r\nWorld", message: 'Add hello world', |