Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit 3143a5d2 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Use the namespace validator for validating all paths

Since the namespacevalidator now knows the difference between a
top-level and another path, this could all be handled there.
parent a7a6c13d6852
......@@ -196,7 +196,7 @@ def update_forks_visibility_level
message: Gitlab::Regex.project_name_regex_message }
validates :path,
presence: true,
project_path: true,
namespace: true,
length: { maximum: 255 },
format: { with: Gitlab::Regex.project_path_regex,
message: Gitlab::Regex.project_path_regex_message },
......
# ProjectPathValidator
#
# Custom validator for GitLab project path values.
#
# Values are checked for formatting and exclusion from a list of reserved path
# names.
#
# This is basically the same as the `NamespaceValidator` but it skips the validation
# of the format with `Gitlab::Regex.namespace_regex`. The format of projects
# is validated in the class itself.
class ProjectPathValidator < NamespaceValidator
def self.valid?(value)
!reserved?(value)
end
def self.reserved?(value, type: :wildcard)
super(value, type: :wildcard)
end
delegate :reserved?, to: :class
def validate_each(record, attribute, value)
if reserved?(value)
record.errors.add(attribute, "#{value} is a reserved name")
end
end
end
......@@ -4,7 +4,7 @@ def matches?(request)
project_path = request.params[:project_id] || request.params[:id]
full_path = namespace_path + '/' + project_path
unless ProjectPathValidator.valid?(project_path)
unless NamespaceValidator.valid_full_path?(full_path)
return false
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment