summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-21 15:49:16 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-24 14:49:23 +0200
commit70f9893ed697873e4c95de4f3ddb3ff8c4fb82f6 (patch)
treed4b79b71f4819b670827fc5088c090b299582db5
parent456e3a7000ecbc45e6a7d3ebb185686a18e4bfc1 (diff)
downloadgitlab-ce-70f9893ed697873e4c95de4f3ddb3ff8c4fb82f6.tar.gz
Explain namespace clearn regex.
-rw-r--r--app/models/namespace.rb5
-rw-r--r--db/migrate/20150421120000_remove_periods_at_ends_of_usernames.rb5
2 files changed, 10 insertions, 0 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 4c760ac6176..f51a14a9514 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 01ea199d618..3057ea3c68c 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.