Lesser Namespace#name validations

Since we use `Namespace#path` to build routes and URLs we can lessen
the restrictions on `Namespace#name` so it can accomodate a user's name.
This commit is contained in:
Bob Van Landuyt 2019-06-24 18:15:03 +02:00
parent 1de47ee373
commit f138acb986
3 changed files with 1 additions and 22 deletions

View file

@ -41,8 +41,7 @@ class Namespace < ApplicationRecord
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
validates :name,
presence: true,
length: { maximum: 255 },
namespace_name: true
length: { maximum: 255 }
validates :description, length: { maximum: 255 }
validates :path,

View file

@ -1,12 +0,0 @@
# frozen_string_literal: true
# NamespaceNameValidator
#
# Custom validator for GitLab namespace name strings.
class NamespaceNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ Gitlab::Regex.namespace_name_regex
record.errors.add(attribute, Gitlab::Regex.namespace_name_regex_message)
end
end
end

View file

@ -4,14 +4,6 @@ module Gitlab
module Regex
extend self
def namespace_name_regex
@namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
end
def namespace_name_regex_message
"can contain only letters, digits, '_', '.', dash and space."
end
def project_name_regex
@project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9c0}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9c0}_\. ]*\z/.freeze
end