From fac1f83fd51d4d6cc6e8a0c571507bca4460b514 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 12:00:08 +0200 Subject: Properly migrate users with usernames like "." or "..". --- app/models/namespace.rb | 6 +++++- db/migrate/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 24363a853d8..4c760ac6176 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 dc38b0eceb7..e2f231ba709 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) -- cgit v1.2.1