summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-11-18 09:55:06 +0000
committerDouwe Maan <douwe@gitlab.com>2016-11-18 09:55:06 +0000
commit75c8faf7ba76563a175766495e132b2f6bdc95d4 (patch)
treedf7c5891980d0e3660d4dd1b3f9134f376be6846
parente252ee5bbf7481e28dd66659940ab6d4ba72b972 (diff)
parentf36e1dbf91180b4382c2878265dd411d70e12713 (diff)
downloadgitlab-ce-75c8faf7ba76563a175766495e132b2f6bdc95d4.tar.gz
Merge branch '24276-usernames-with-dots' into 'master'
Allow registering users where the username contains dots (.) ## What does this MR do? - Allow registering users whose usernames contains dots `.` - This can currently be done by registering with a username containing no dots, and then editing the username to have dots in the user's profile settings. ## Does this MR meet the acceptance criteria? - [#24276/!7500] Unable to register names with dot - [x] Implementation - [x] Tests - [x] Added - [x] [Passing](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7500/builds) - [x] Meta - [x] CHANGELOG entry created - [x] Documentation created/updated - [x] API support added - [x] Branch has no merge conflicts with `master` - [x] Squashed related commits together - [x] Review - [x] Endboss - [x] Use `Gitlab::Regex::NAMESPACE_REGEX_STR` instead of a hardcoded pattern - [x] Define `NAMESPACE_REGEX_STR` in terms of `NAMESPACE_REGEX_STR_JS` - [ ] Wait for merge ## What are the relevant issue numbers? - Closes #24276 See merge request !7500
-rw-r--r--app/views/devise/shared/_signup_box.html.haml2
-rw-r--r--changelogs/unreleased/24276-usernames-with-dots.yml4
-rw-r--r--lib/gitlab/regex.rb9
-rw-r--r--spec/features/users_spec.rb19
4 files changed, 29 insertions, 5 deletions
diff --git a/app/views/devise/shared/_signup_box.html.haml b/app/views/devise/shared/_signup_box.html.haml
index 7c68e3266e5..3133f6de2e8 100644
--- a/app/views/devise/shared/_signup_box.html.haml
+++ b/app/views/devise/shared/_signup_box.html.haml
@@ -8,7 +8,7 @@
= f.text_field :name, class: "form-control top", required: true, title: "This field is required."
%div.username.form-group
= f.label :username
- = f.text_field :username, class: "form-control middle", pattern: "[a-zA-Z0-9]+", required: true, title: 'Please create a username with only alphanumeric characters.'
+ = f.text_field :username, class: "form-control middle", pattern: Gitlab::Regex::NAMESPACE_REGEX_STR_SIMPLE, required: true, title: 'Please create a username with only alphanumeric characters.'
%p.validation-error.hide Username is already taken.
%p.validation-success.hide Username is available.
%p.validation-pending.hide Checking username availability...
diff --git a/changelogs/unreleased/24276-usernames-with-dots.yml b/changelogs/unreleased/24276-usernames-with-dots.yml
new file mode 100644
index 00000000000..9aeeb33e9ef
--- /dev/null
+++ b/changelogs/unreleased/24276-usernames-with-dots.yml
@@ -0,0 +1,4 @@
+---
+title: Allow registering users whose username contains dots
+merge_request: 7500
+author: Timothy Andrew
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index 155ca47e04c..47ea8b7e82e 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -2,7 +2,14 @@ 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_])(?<!\.git|\.atom)'.freeze
+ # The namespace regex is used in Javascript to validate usernames in the "Register" form. However, Javascript
+ # does not support the negative lookbehind assertion (?<!) that disallows usernames ending in `.git` and `.atom`.
+ # Since this is a non-trivial problem to solve in Javascript (heavily complicate the regex, modify view code to
+ # allow non-regex validatiions, etc), `NAMESPACE_REGEX_STR_SIMPLE` serves as a Javascript-compatible version of
+ # `NAMESPACE_REGEX_STR`, with the negative lookbehind assertion removed. This means that the client-side validation
+ # will pass for usernames ending in `.atom` and `.git`, but will be caught by the server-side validation.
+ NAMESPACE_REGEX_STR_SIMPLE = '[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_]'.freeze
+ NAMESPACE_REGEX_STR = "(?:#{NAMESPACE_REGEX_STR_SIMPLE})(?<!\.git|\.atom)".freeze
def namespace_regex
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb
index 111ca7f7a70..afa98f3f715 100644
--- a/spec/features/users_spec.rb
+++ b/spec/features/users_spec.rb
@@ -74,16 +74,29 @@ feature 'Users', feature: true, js: true do
visit new_user_session_path
click_link 'Register'
end
+
+ scenario 'doesn\'t show an error border if the username is available' do
+ fill_in username_input, with: 'new-user'
+ wait_for_ajax
+ expect(find('.username')).not_to have_css '.gl-field-error-outline'
+ end
+
+ scenario 'does not show an error border if the username contains dots (.)' do
+ fill_in username_input, with: 'new.user.username'
+ wait_for_ajax
+ expect(find('.username')).not_to have_css '.gl-field-error-outline'
+ end
+
scenario 'shows an error border if the username already exists' do
fill_in username_input, with: user.username
wait_for_ajax
expect(find('.username')).to have_css '.gl-field-error-outline'
end
- scenario 'doesn\'t show an error border if the username is available' do
- fill_in username_input, with: 'new-user'
+ scenario 'shows an error border if the username contains special characters' do
+ fill_in username_input, with: 'new$user!username'
wait_for_ajax
- expect(find('#new_user_username')).not_to have_css '.gl-field-error-outline'
+ expect(find('.username')).to have_css '.gl-field-error-outline'
end
end