Properly migrate users with usernames like "." or "..".

This commit is contained in:
Douwe Maan 2015-04-21 12:00:08 +02:00
parent c0116926c7
commit fac1f83fd5
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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)