Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-24 17:16:08 +0300
committerDouwe Maan <douwe@gitlab.com>2015-04-24 17:16:08 +0300
commitb8c4215969a45370ad37a67a8a52d16d7eeecba4 (patch)
tree523250950118f09e4b9a6cd6dbebb1350fc2cf6d /app
parent62117f2f25646009fb5b20d7a215d7d697ce3231 (diff)
parent5f839770e720dc2f176c51d4635dceb6c34ff97a (diff)
Merge branch 'username-period-again' into 'master'
Don't allow username to end in period. Fixes #2174 and #2249. cc @jacobvosmaer Please review and test with the GitLab.com dump. See merge request !1786
Diffstat (limited to 'app')
-rw-r--r--app/models/namespace.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index e1de114375e..211dfa76b81 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -60,15 +60,24 @@ 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.
+ # 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