From 1d2a5ee1887bd767ede8c84babb1868954c38e6f Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 11:52:54 +0200 Subject: [PATCH 1/9] Revert "Revert disallowing usernames to end in period." This reverts commit c75c6b840ba9ed82bb01eca52e968c2b0ec985e6. --- CHANGELOG | 1 + ...047_remove_periods_at_ends_of_usernames.rb | 76 +++++++++++++++++++ lib/gitlab/regex.rb | 4 +- 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb diff --git a/CHANGELOG b/CHANGELOG index 0d6b0f2d94..47eb152ad7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -97,6 +97,7 @@ v 7.10.0 (unreleased) - Fix admin user projects lists. - Don't leak private group existence by redirecting from namespace controller to group controller. - Ability to skip some items from backup (database, respositories or uploads) + - Fix "Hello @username." references not working by no longer allowing usernames to end in period. - Archive repositories in background worker. - Import GitHub, Bitbucket or GitLab.com projects owned by authenticated user into current namespace. - Project labels are now available over the API under the "tag_list" field (Cristian Medina) diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb new file mode 100644 index 0000000000..dc38b0eceb --- /dev/null +++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb @@ -0,0 +1,76 @@ +class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration + include Gitlab::ShellAdapter + + class Namespace < ActiveRecord::Base + class << self + def find_by_path_or_name(path) + find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase) + end + + def clean_path(path) + path = path.dup + path.gsub!(/@.*\z/, "") + path.gsub!(/\.git\z/, "") + path.gsub!(/\A-+/, "") + path.gsub!(/\.+\z/, "") + path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") + + counter = 0 + base = path + while Namespace.find_by_path_or_name(path) + counter += 1 + path = "#{base}#{counter}" + end + + path + end + end + end + + def up + changed_paths = {} + + select_all("SELECT id, username FROM users WHERE username LIKE '%.'").each do |user| + username_was = user["username"] + username = Namespace.clean_path(username_was) + changed_paths[username_was] = username + + username = quote_string(username) + execute "UPDATE users SET username = '#{username}' WHERE id = #{user["id"]}" + execute "UPDATE namespaces SET path = '#{username}', name = '#{username}' WHERE type IS NULL AND owner_id = #{user["id"]}" + end + + select_all("SELECT id, path FROM namespaces WHERE type = 'Group' AND path LIKE '%.'").each do |group| + path_was = group["path"] + path = Namespace.clean_path(path_was) + changed_paths[path_was] = path + + path = quote_string(path) + execute "UPDATE namespaces SET path = '#{path}' WHERE id = #{group["id"]}" + end + + changed_paths.each do |path_was, path| + if gitlab_shell.mv_namespace(path_was, path) + # If repositories moved successfully we need to remove old satellites + # and send update instructions to users. + # However we cannot allow rollback since we moved namespace dir + # So we basically we mute exceptions in next actions + begin + gitlab_shell.rm_satellites(path_was) + # We cannot send update instructions since models and mailers + # can't safely be used from migrations as they may be written for + # later versions of the database. + # send_update_instructions + rescue + # Returning false does not rollback after_* transaction but gives + # us information about failing some of tasks + false + end + else + # if we cannot move namespace directory we should rollback + # db changes in order to prevent out of sync between db and fs + raise Exception.new('namespace directory cannot be moved') + end + end + end +end diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 9aeed5e693..0571574aa4 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -2,7 +2,7 @@ module Gitlab module Regex extend self - NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*)'.freeze + NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze def namespace_regex @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze @@ -10,7 +10,7 @@ module Gitlab def namespace_regex_message "can contain only letters, digits, '_', '-' and '.'. " \ - "Cannot start with '-'." \ + "Cannot start with '-' or end in '.'." \ end From 164a29df86f70910ac0bc6bd29f0fe6f4037b56e Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 11:53:32 +0200 Subject: [PATCH 2/9] Move changelog item tot 7.11. --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 47eb152ad7..e5c06776ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v 7.11.0 (unreleased) - Ignore invalid lines in .gitmodules - Fix "Cannot move project" error message from popping up after a successful transfer (Stan Hu) - Redirect to sign in page after signing out. + - Fix "Hello @username." references not working by no longer allowing usernames to end in period. - - Add "Reply quoting selected text" shortcut key (`r`) - Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention. @@ -97,7 +98,6 @@ v 7.10.0 (unreleased) - Fix admin user projects lists. - Don't leak private group existence by redirecting from namespace controller to group controller. - Ability to skip some items from backup (database, respositories or uploads) - - Fix "Hello @username." references not working by no longer allowing usernames to end in period. - Archive repositories in background worker. - Import GitHub, Bitbucket or GitLab.com projects owned by authenticated user into current namespace. - Project labels are now available over the API under the "tag_list" field (Cristian Medina) From c0116926c743818b2593474946abb40b56d8fefa Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 11:58:45 +0200 Subject: [PATCH 3/9] Rename namespace_regex to namespace_path_regex. --- app/models/namespace.rb | 4 ++-- app/models/user.rb | 4 ++-- lib/gitlab/markdown/cross_project_reference.rb | 2 +- lib/gitlab/markdown/user_reference_filter.rb | 2 +- lib/gitlab/reference_extractor.rb | 2 +- lib/gitlab/regex.rb | 8 ++++---- spec/requests/api/users_spec.rb | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e1de114375..24363a853d 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -33,8 +33,8 @@ class Namespace < ActiveRecord::Base presence: true, length: { within: 1..255 }, exclusion: { in: Gitlab::Blacklist.path }, - format: { with: Gitlab::Regex.namespace_regex, - message: Gitlab::Regex.namespace_regex_message } + format: { with: Gitlab::Regex.namespace_path_regex, + message: Gitlab::Regex.namespace_path_regex_message } delegate :name, to: :owner, allow_nil: true, prefix: true diff --git a/app/models/user.rb b/app/models/user.rb index d6b93afe73..7d7faa64f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -131,8 +131,8 @@ class User < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false }, exclusion: { in: Gitlab::Blacklist.path }, - format: { with: Gitlab::Regex.namespace_regex, - message: Gitlab::Regex.namespace_regex_message } + format: { with: Gitlab::Regex.namespace_path_regex, + message: Gitlab::Regex.namespace_path_regex_message } validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true validate :namespace_uniq, if: ->(user) { user.username_changed? } diff --git a/lib/gitlab/markdown/cross_project_reference.rb b/lib/gitlab/markdown/cross_project_reference.rb index c436fabd65..261fc0feb0 100644 --- a/lib/gitlab/markdown/cross_project_reference.rb +++ b/lib/gitlab/markdown/cross_project_reference.rb @@ -3,7 +3,7 @@ module Gitlab # Common methods for ReferenceFilters that support an optional cross-project # reference. module CrossProjectReference - NAMING_PATTERN = Gitlab::Regex::NAMESPACE_REGEX_STR + NAMING_PATTERN = Gitlab::Regex::NAMESPACE_PATH_REGEX_STR PROJECT_PATTERN = "(?#{NAMING_PATTERN}/#{NAMING_PATTERN})" # Given a cross-project reference string, get the Project record diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb index 5fc8ed55fe..d7885fdeef 100644 --- a/lib/gitlab/markdown/user_reference_filter.rb +++ b/lib/gitlab/markdown/user_reference_filter.rb @@ -22,7 +22,7 @@ module Gitlab end # Pattern used to extract `@user` user references from text - USER_PATTERN = /@(?#{Gitlab::Regex::NAMESPACE_REGEX_STR})/ + USER_PATTERN = /@(?#{Gitlab::Regex::NAMESPACE_PATH_REGEX_STR})/ def call replace_text_nodes_matching(USER_PATTERN) do |content| diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index 949dd5d26b..1d6df9a29f 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -85,7 +85,7 @@ module Gitlab private - NAME_STR = Gitlab::Regex::NAMESPACE_REGEX_STR + NAME_STR = Gitlab::Regex::NAMESPACE_PATH_REGEX_STR PROJ_STR = "(?#{NAME_STR}/#{NAME_STR})" REFERENCE_PATTERN = %r{ diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 0571574aa4..e5f5482a22 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -2,13 +2,13 @@ module Gitlab module Regex extend self - NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze + NAMESPACE_PATH_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze - def namespace_regex - @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze + def namespace_path_regex + @namespace_path_regex ||= /\A#{NAMESPACE_PATH_REGEX_STR}\z/.freeze end - def namespace_regex_message + def namespace_path_regex_message "can contain only letters, digits, '_', '-' and '.'. " \ "Cannot start with '-' or end in '.'." \ end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 327f3e6d23..cb41ea4491 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -145,7 +145,7 @@ describe API::API, api: true do expect(json_response['message']['projects_limit']). to eq(['must be greater than or equal to 0']) expect(json_response['message']['username']). - to eq([Gitlab::Regex.send(:namespace_regex_message)]) + to eq([Gitlab::Regex.send(:namespace_path_regex_message)]) end it "shouldn't available for non admin users" do @@ -271,7 +271,7 @@ describe API::API, api: true do expect(json_response['message']['projects_limit']). to eq(['must be greater than or equal to 0']) expect(json_response['message']['username']). - to eq([Gitlab::Regex.send(:namespace_regex_message)]) + to eq([Gitlab::Regex.send(:namespace_path_regex_message)]) end context "with existing user" do From fac1f83fd51d4d6cc6e8a0c571507bca4460b514 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 12:00:08 +0200 Subject: [PATCH 4/9] Properly migrate users with usernames like "." or "..". --- app/models/namespace.rb | 6 +++++- .../20150324133047_remove_periods_at_ends_of_usernames.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 24363a853d..4c760ac617 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -66,9 +66,13 @@ class Namespace < ActiveRecord::Base path.gsub!(/\.+\z/, "") path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") + # Users with the great usernames of "." or ".." would end up with a blank username. + # Work around that by setting their username to "blank", followed by a counter. + path = "blank" if path.blank? + counter = 0 base = path - while Namespace.by_path(path).present? + while Namespace.find_by_path_or_name(path) counter += 1 path = "#{base}#{counter}" end diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb index dc38b0eceb..e2f231ba70 100644 --- a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb +++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb @@ -15,6 +15,10 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration path.gsub!(/\.+\z/, "") path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") + # Users with the great usernames of "." or ".." would end up with a blank username. + # Work around that by setting their username to "blank", followed by a counter. + path = "blank" if path.blank? + counter = 0 base = path while Namespace.find_by_path_or_name(path) From 4934bc031205c668d4405c2a6faaee32367234d6 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 12:00:32 +0200 Subject: [PATCH 5/9] Change migration timestamp. --- ...s.rb => 20150421120000_remove_periods_at_ends_of_usernames.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20150324133047_remove_periods_at_ends_of_usernames.rb => 20150421120000_remove_periods_at_ends_of_usernames.rb} (100%) diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb similarity index 100% rename from db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb rename to db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb From 2fd47a0e95da2ef2dada1012f09d6c0d1b7431a9 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:01:48 +0200 Subject: [PATCH 6/9] Don't attempt to move if original path only contains periods. --- .../20150421120000_remove_periods_at_ends_of_usernames.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb index e2f231ba70..01ea199d61 100644 --- a/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb +++ b/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb @@ -54,6 +54,9 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration end changed_paths.each do |path_was, path| + # Don't attempt to move if original path only contains periods. + next if path_was =~ /\A\.+\z/ + if gitlab_shell.mv_namespace(path_was, path) # If repositories moved successfully we need to remove old satellites # and send update instructions to users. From 456e3a7000ecbc45e6a7d3ebb185686a18e4bfc1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:01:52 +0200 Subject: [PATCH 7/9] Update schema. --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 2b7e27e3a3..6db7e386c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150417122318) do +ActiveRecord::Schema.define(version: 20150421120000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 70f9893ed697873e4c95de4f3ddb3ff8c4fb82f6 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:49:16 +0200 Subject: [PATCH 8/9] Explain namespace clearn regex. --- app/models/namespace.rb | 5 +++++ .../20150421120000_remove_periods_at_ends_of_usernames.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 4c760ac617..f51a14a951 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -60,10 +60,15 @@ class Namespace < ActiveRecord::Base def clean_path(path) path = path.dup + # Get the email username by removing everything after an `@` sign. path.gsub!(/@.*\z/, "") + # Usernames can't end in .git, so remove it. path.gsub!(/\.git\z/, "") + # Remove dashes at the start of the username. path.gsub!(/\A-+/, "") + # Remove periods at the end of the username. path.gsub!(/\.+\z/, "") + # Remove everything that's not in the list of allowed characters. path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") # Users with the great usernames of "." or ".." would end up with a blank username. diff --git a/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb index 01ea199d61..3057ea3c68 100644 --- a/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb +++ b/db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb @@ -9,10 +9,15 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration def clean_path(path) path = path.dup + # Get the email username by removing everything after an `@` sign. path.gsub!(/@.*\z/, "") + # Usernames can't end in .git, so remove it. path.gsub!(/\.git\z/, "") + # Remove dashes at the start of the username. path.gsub!(/\A-+/, "") + # Remove periods at the end of the username. path.gsub!(/\.+\z/, "") + # Remove everything that's not in the list of allowed characters. path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") # Users with the great usernames of "." or ".." would end up with a blank username. From 5f839770e720dc2f176c51d4635dceb6c34ff97a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 24 Apr 2015 15:16:38 +0200 Subject: [PATCH 9/9] Revert "Rename namespace_regex to namespace_path_regex." This reverts commit c0116926c743818b2593474946abb40b56d8fefa. --- app/models/namespace.rb | 4 ++-- app/models/user.rb | 4 ++-- lib/gitlab/markdown/cross_project_reference.rb | 2 +- lib/gitlab/markdown/user_reference_filter.rb | 2 +- lib/gitlab/reference_extractor.rb | 2 +- lib/gitlab/regex.rb | 8 ++++---- spec/requests/api/users_spec.rb | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index f51a14a951..211dfa76b8 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -33,8 +33,8 @@ class Namespace < ActiveRecord::Base presence: true, length: { within: 1..255 }, exclusion: { in: Gitlab::Blacklist.path }, - format: { with: Gitlab::Regex.namespace_path_regex, - message: Gitlab::Regex.namespace_path_regex_message } + format: { with: Gitlab::Regex.namespace_regex, + message: Gitlab::Regex.namespace_regex_message } delegate :name, to: :owner, allow_nil: true, prefix: true diff --git a/app/models/user.rb b/app/models/user.rb index 7d7faa64f7..d6b93afe73 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -131,8 +131,8 @@ class User < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false }, exclusion: { in: Gitlab::Blacklist.path }, - format: { with: Gitlab::Regex.namespace_path_regex, - message: Gitlab::Regex.namespace_path_regex_message } + format: { with: Gitlab::Regex.namespace_regex, + message: Gitlab::Regex.namespace_regex_message } validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true validate :namespace_uniq, if: ->(user) { user.username_changed? } diff --git a/lib/gitlab/markdown/cross_project_reference.rb b/lib/gitlab/markdown/cross_project_reference.rb index 261fc0feb0..c436fabd65 100644 --- a/lib/gitlab/markdown/cross_project_reference.rb +++ b/lib/gitlab/markdown/cross_project_reference.rb @@ -3,7 +3,7 @@ module Gitlab # Common methods for ReferenceFilters that support an optional cross-project # reference. module CrossProjectReference - NAMING_PATTERN = Gitlab::Regex::NAMESPACE_PATH_REGEX_STR + NAMING_PATTERN = Gitlab::Regex::NAMESPACE_REGEX_STR PROJECT_PATTERN = "(?#{NAMING_PATTERN}/#{NAMING_PATTERN})" # Given a cross-project reference string, get the Project record diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb index d7885fdeef..5fc8ed55fe 100644 --- a/lib/gitlab/markdown/user_reference_filter.rb +++ b/lib/gitlab/markdown/user_reference_filter.rb @@ -22,7 +22,7 @@ module Gitlab end # Pattern used to extract `@user` user references from text - USER_PATTERN = /@(?#{Gitlab::Regex::NAMESPACE_PATH_REGEX_STR})/ + USER_PATTERN = /@(?#{Gitlab::Regex::NAMESPACE_REGEX_STR})/ def call replace_text_nodes_matching(USER_PATTERN) do |content| diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index 1d6df9a29f..949dd5d26b 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -85,7 +85,7 @@ module Gitlab private - NAME_STR = Gitlab::Regex::NAMESPACE_PATH_REGEX_STR + NAME_STR = Gitlab::Regex::NAMESPACE_REGEX_STR PROJ_STR = "(?#{NAME_STR}/#{NAME_STR})" REFERENCE_PATTERN = %r{ diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index e5f5482a22..0571574aa4 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -2,13 +2,13 @@ module Gitlab module Regex extend self - NAMESPACE_PATH_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze + NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze - def namespace_path_regex - @namespace_path_regex ||= /\A#{NAMESPACE_PATH_REGEX_STR}\z/.freeze + def namespace_regex + @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze end - def namespace_path_regex_message + def namespace_regex_message "can contain only letters, digits, '_', '-' and '.'. " \ "Cannot start with '-' or end in '.'." \ end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index cb41ea4491..327f3e6d23 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -145,7 +145,7 @@ describe API::API, api: true do expect(json_response['message']['projects_limit']). to eq(['must be greater than or equal to 0']) expect(json_response['message']['username']). - to eq([Gitlab::Regex.send(:namespace_path_regex_message)]) + to eq([Gitlab::Regex.send(:namespace_regex_message)]) end it "shouldn't available for non admin users" do @@ -271,7 +271,7 @@ describe API::API, api: true do expect(json_response['message']['projects_limit']). to eq(['must be greater than or equal to 0']) expect(json_response['message']['username']). - to eq([Gitlab::Regex.send(:namespace_path_regex_message)]) + to eq([Gitlab::Regex.send(:namespace_regex_message)]) end context "with existing user" do