diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-06-24 18:15:03 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-07-09 18:09:45 +0200 |
commit | f138acb9866fa86f16e1db14c23e48c2e9f2b38b (patch) | |
tree | 4cd1f49c4227775b47a68de597eee51dadecf3a7 | |
parent | 1de47ee373650f197c1e4c558946dd6d8149e7e5 (diff) | |
download | gitlab-ce-f138acb9866fa86f16e1db14c23e48c2e9f2b38b.tar.gz |
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.
-rw-r--r-- | app/models/namespace.rb | 3 | ||||
-rw-r--r-- | app/validators/namespace_name_validator.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/regex.rb | 8 |
3 files changed, 1 insertions, 22 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index af50293a179..1d95590bac9 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -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, diff --git a/app/validators/namespace_name_validator.rb b/app/validators/namespace_name_validator.rb deleted file mode 100644 index fb1c241037c..00000000000 --- a/app/validators/namespace_name_validator.rb +++ /dev/null @@ -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 diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 7a1a2eaf6c0..e43147a3f37 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -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 |