{{#if model.can_edit_name}}
- {{text-field value=newNameInput classNames="input-xxlarge"}}
+ {{text-field value=newNameInput classNames="input-xxlarge" maxlength="255"}}
{{else}}
{{model.name}}
{{/if}}
diff --git a/app/models/user.rb b/app/models/user.rb
index 2a6f303c926..e3d83110da7 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1402,10 +1402,11 @@ class User < ActiveRecord::Base
end
def name_validator
- if name.present? &&
- (confirm_password?(name) || confirm_password?(name&.downcase))
-
- errors.add(:name, :same_as_password)
+ if name.present?
+ name_pw = name[0...User.max_password_length]
+ if confirm_password?(name_pw) || confirm_password?(name_pw.downcase)
+ errors.add(:name, :same_as_password)
+ end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 9d722ae9477..ffcd7cd1a01 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -65,6 +65,11 @@ describe User do
expect(user.errors.full_messages.first)
.to include(user_error_message(:name, :same_as_password))
end
+
+ it "doesn't raise an error if the name is longer than the max password length" do
+ user.name = 'x' * 220
+ expect(user).to be_valid
+ end
end
describe 'emails' do