Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reallow project paths ending in periods
- Loading branch information
Showing
18 changed files
with
223 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class AbstractPathValidator < ActiveModel::EachValidator | ||
extend Gitlab::EncodingHelper | ||
|
||
def self.path_regex | ||
raise NotImplementedError | ||
end | ||
|
||
def self.format_regex | ||
raise NotImplementedError | ||
end | ||
|
||
def self.format_error_message | ||
raise NotImplementedError | ||
end | ||
|
||
def self.full_path(record, value) | ||
value | ||
end | ||
|
||
def self.valid_path?(path) | ||
encode!(path) | ||
"#{path}/" =~ path_regex | ||
end | ||
|
||
def validate_each(record, attribute, value) | ||
unless value =~ self.class.format_regex | ||
record.errors.add(attribute, self.class.format_error_message) | ||
return | ||
end | ||
|
||
full_path = self.class.full_path(record, value) | ||
return unless full_path | ||
|
||
unless self.class.valid_path?(full_path) | ||
record.errors.add(attribute, "#{value} is a reserved name") | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class NamespacePathValidator < AbstractPathValidator | ||
extend Gitlab::EncodingHelper | ||
|
||
def self.path_regex | ||
Gitlab::PathRegex.full_namespace_path_regex | ||
end | ||
|
||
def self.format_regex | ||
Gitlab::PathRegex.namespace_format_regex | ||
end | ||
|
||
def self.format_error_message | ||
Gitlab::PathRegex.namespace_format_message | ||
end | ||
|
||
def self.full_path(record, value) | ||
record.build_full_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ProjectPathValidator < AbstractPathValidator | ||
extend Gitlab::EncodingHelper | ||
|
||
def self.path_regex | ||
Gitlab::PathRegex.full_project_path_regex | ||
end | ||
|
||
def self.format_regex | ||
Gitlab::PathRegex.project_path_format_regex | ||
end | ||
|
||
def self.format_error_message | ||
Gitlab::PathRegex.project_path_format_message | ||
end | ||
|
||
def self.full_path(record, value) | ||
record.build_full_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class UserPathValidator < AbstractPathValidator | ||
extend Gitlab::EncodingHelper | ||
|
||
def self.path_regex | ||
Gitlab::PathRegex.root_namespace_path_regex | ||
end | ||
|
||
def self.format_regex | ||
Gitlab::PathRegex.namespace_format_regex | ||
end | ||
|
||
def self.format_error_message | ||
Gitlab::PathRegex.namespace_format_message | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
changelogs/unreleased/dm-reallow-project-path-ending-in-period.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Reallow project paths ending in periods | ||
merge_request: | ||
author: | ||
type: fixed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe NamespacePathValidator do | ||
let(:validator) { described_class.new(attributes: [:path]) } | ||
|
||
describe '.valid_path?' do | ||
it 'handles invalid utf8' do | ||
expect(described_class.valid_path?("a\0weird\255path")).to be_falsey | ||
end | ||
end | ||
|
||
describe '#validates_each' do | ||
it 'adds a message when the path is not in the correct format' do | ||
group = build(:group) | ||
|
||
validator.validate_each(group, :path, "Path with spaces, and comma's!") | ||
|
||
expect(group.errors[:path]).to include(Gitlab::PathRegex.namespace_format_message) | ||
end | ||
|
||
it 'adds a message when the path is reserved when creating' do | ||
group = build(:group, path: 'help') | ||
|
||
validator.validate_each(group, :path, 'help') | ||
|
||
expect(group.errors[:path]).to include('help is a reserved name') | ||
end | ||
|
||
it 'adds a message when the path is reserved when updating' do | ||
group = create(:group) | ||
group.path = 'help' | ||
|
||
validator.validate_each(group, :path, 'help') | ||
|
||
expect(group.errors[:path]).to include('help is a reserved name') | ||
end | ||
end | ||
end |
Oops, something went wrong.