Skip to content

Commit

Permalink
Validate length of user's name attribute
Browse files Browse the repository at this point in the history
This attribute is a text column, so it could be very long even in a
MySQL database. Limit it to a generous length.
  • Loading branch information
mvz committed Aug 14, 2022
1 parent ca46da2 commit 29a5837
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions publify_core/app/models/user.rb
Expand Up @@ -22,6 +22,7 @@ class User < ApplicationRecord
validates :email, :login, presence: true
validates :login, length: { in: 3..40 }
validates_default_string_length :email, :text_filter_name
validates :name, length: { maximum: 2048 }

belongs_to :resource, optional: true
has_many :notifications, foreign_key: "notify_user_id"
Expand Down
4 changes: 4 additions & 0 deletions publify_core/spec/models/user_spec.rb
Expand Up @@ -49,6 +49,10 @@
expect(user).to validate_length_of(:email).is_at_most(255)
end

it "requires name to not be too long" do
expect(user).to validate_length_of(:name).is_at_most(2048)
end

it "requires first name to not be too long" do
expect(user).to validate_length_of(:firstname).is_at_most(256)
end
Expand Down

0 comments on commit 29a5837

Please sign in to comment.