Merge branch '32408-allow-creation-of-files-and-dirs-with-spaces-in-web-ui' into 'master'

Make filename and path creation compatible with UNIX in web UI

Closes #21362

See merge request !12608
This commit is contained in:
Douwe Maan 2017-07-05 20:21:58 +00:00
commit 793ce6fef6
9 changed files with 16 additions and 40 deletions

View file

@ -37,9 +37,7 @@ class Snippet < ActiveRecord::Base
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { maximum: 255 } validates :title, presence: true, length: { maximum: 255 }
validates :file_name, validates :file_name,
length: { maximum: 255 }, length: { maximum: 255 }
format: { with: Gitlab::Regex.file_name_regex,
message: Gitlab::Regex.file_name_regex_message }
validates :content, presence: true validates :content, presence: true
validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values } validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values }

View file

@ -0,0 +1,4 @@
---
title: Allow creation of files and directories with spaces through Web UI
merge_request: 12608
author:

View file

@ -130,16 +130,6 @@ Feature: Project Source Browse Files
When I click on "Changes" tab When I click on "Changes" tab
Then I can see the new text file Then I can see the new text file
@javascript
Scenario: If I enter an illegal file name I see an error message
Given I click on "New file" link in repo
And I fill the new file name with an illegal name
And I edit code
And I fill the commit message
And I click on "Commit changes"
Then I am on the new file page
And I see "Path can contain only..."
@javascript @javascript
Scenario: I can create file with a directory name Scenario: I can create file with a directory name
Given I click on "New file" link in repo Given I click on "New file" link in repo

View file

@ -92,10 +92,6 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
fill_in :branch_name, with: 'new_branch_name', visible: true fill_in :branch_name, with: 'new_branch_name', visible: true
end end
step 'I fill the new file name with an illegal name' do
fill_in :file_name, with: 'Spaces Not Allowed'
end
step 'I fill the new file name with a new directory' do step 'I fill the new file name with a new directory' do
fill_in :file_name, with: new_file_name_with_directory fill_in :file_name, with: new_file_name_with_directory
end end

View file

@ -110,10 +110,6 @@ module Gitlab
if segment == '..' if segment == '..'
raise IndexError, 'Path cannot include directory traversal' raise IndexError, 'Path cannot include directory traversal'
end end
unless segment =~ Gitlab::Regex.file_name_regex
raise IndexError, "Path #{Gitlab::Regex.file_name_regex_message}"
end
end end
pathname.to_s pathname.to_s

View file

@ -19,14 +19,6 @@ module Gitlab
"It must start with letter, digit, emoji or '_'." "It must start with letter, digit, emoji or '_'."
end end
def file_name_regex
@file_name_regex ||= /\A[[[:alnum:]]_\-\.\@\+]*\z/.freeze
end
def file_name_regex_message
"can contain only letters, digits, '_', '-', '@', '+' and '.'."
end
def container_registry_reference_regex def container_registry_reference_regex
Gitlab::PathRegex.git_reference_regex Gitlab::PathRegex.git_reference_regex
end end

View file

@ -30,11 +30,6 @@ feature 'User wants to create a file', feature: true do
expect(page).to have_content 'The file has been successfully created' expect(page).to have_content 'The file has been successfully created'
end end
scenario 'file name contains invalid characters' do
submit_new_file(file_name: '\\')
expect(page).to have_content 'Path can contain only'
end
scenario 'file name contains directory traversal' do scenario 'file name contains directory traversal' do
submit_new_file(file_name: '../README.md') submit_new_file(file_name: '../README.md')
expect(page).to have_content 'Path cannot include directory traversal' expect(page).to have_content 'Path cannot include directory traversal'

View file

@ -14,12 +14,6 @@ describe Gitlab::Regex, lib: true do
it { is_expected.not_to match('?gitlab') } it { is_expected.not_to match('?gitlab') }
end end
describe '.file_name_regex' do
subject { described_class.file_name_regex }
it { is_expected.to match('foo@bar') }
end
describe '.environment_slug_regex' do describe '.environment_slug_regex' do
subject { described_class.environment_name_regex } subject { described_class.environment_name_regex }

View file

@ -347,6 +347,17 @@ describe Repository, models: true do
expect(blob.data).to eq('Changelog!') expect(blob.data).to eq('Changelog!')
end end
it 'creates new file and dir when file_path has a forward slash' do
expect do
repository.create_file(user, 'new_dir/new_file.txt', 'File!',
message: 'Create new_file with new_dir',
branch_name: 'master')
end.to change { repository.commits('master').count }.by(1)
expect(repository.tree('master', 'new_dir').path).to eq('new_dir')
expect(repository.blob_at('master', 'new_dir/new_file.txt').data).to eq('File!')
end
it 'respects the autocrlf setting' do it 'respects the autocrlf setting' do
repository.create_file(user, 'hello.txt', "Hello,\r\nWorld", repository.create_file(user, 'hello.txt', "Hello,\r\nWorld",
message: 'Add hello world', message: 'Add hello world',