diff options
author | Surinna Curtis <ekiru.0@gmail.com> | 2017-06-25 22:23:53 -0500 |
---|---|---|
committer | Surinna Curtis <ekiru.0@gmail.com> | 2017-06-26 09:34:31 -0500 |
commit | 4f36aad6e8e1dad6b9907b62a200919fbe0d4ebe (patch) | |
tree | 6e47afb596ab275ab5d882229adb1cdaaacdb493 /app/models | |
parent | 56ca33a6d3c01e2ee4a6a20fb4d0b35bc09fc88b (diff) |
don't count bio metadata against bio length on server
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 14c90cfc0..49d2c88f6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -60,7 +60,7 @@ class Account < ApplicationRecord validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? } validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? } - validates :note, length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? } + validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? } # Timelines has_many :stream_entries, inverse_of: :account, dependent: :destroy @@ -251,6 +251,22 @@ class Account < ApplicationRecord self.public_key = keypair.public_key.to_pem end + YAML_START = "---\r\n" + YAML_END = "\r\n...\r\n" + + def note_length_does_not_exceed_length_limit + note_without_metadata = note + if note.start_with? YAML_START + idx = note.index YAML_END + unless idx.nil? + note_without_metadata = note[(idx + YAML_END.length) .. -1] + end + end + if note_without_metadata.mb_chars.grapheme_length > 500 + errors.add(:note, "can't be longer than 500 graphemes") + end + end + def normalize_domain return if local? |