diff --git a/app/logical/user_name_validator.rb b/app/logical/user_name_validator.rb index e55687103..8d44cb064 100644 --- a/app/logical/user_name_validator.rb +++ b/app/logical/user_name_validator.rb @@ -11,7 +11,8 @@ class UserNameValidator < ActiveModel::EachValidator name = value rec.errors.add(attr, "already exists") if User.find_by_name(name).present? - rec.errors.add(attr, "must be 2 to 100 characters long") if !name.length.between?(2, 100) + rec.errors.add(attr, "must be more than 1 character long") if name.length <= 1 + rec.errors.add(attr, "must be less than 25 characters long") if name.length >= 25 rec.errors.add(attr, "cannot have whitespace or colons") if name =~ /[[:space:]]|:/ rec.errors.add(attr, "cannot begin or end with an underscore") if name =~ /\A_|_\z/ rec.errors.add(attr, "is not allowed") if name =~ Regexp.union(Danbooru.config.user_name_blacklist) diff --git a/test/factories/user.rb b/test/factories/user.rb index a9bbe1c77..6782bc73a 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory(:user, aliases: [:creator, :updater]) do - name { SecureRandom.uuid } + name { SecureRandom.uuid.first(20) } password {"password"} level {20} last_logged_in_at {Time.now}