]> cat aescling's git repositories - mastodon.git/blob - app/validators/note_length_validator.rb
Add `details` to error response for `POST /api/v1/accounts` in REST API (#15803)
[mastodon.git] / app / validators / note_length_validator.rb
1 # frozen_string_literal: true
2
3 class NoteLengthValidator < ActiveModel::EachValidator
4 def validate_each(record, attribute, value)
5 record.errors.add(attribute, :too_long, message: I18n.t('statuses.over_character_limit', max: options[:maximum]), count: options[:maximum]) if too_long?(value)
6 end
7
8 private
9
10 def too_long?(value)
11 countable_text(value).mb_chars.grapheme_length > options[:maximum]
12 end
13
14 def countable_text(value)
15 return '' if value.nil?
16
17 value.dup.tap do |new_text|
18 new_text.gsub!(FetchLinkCardService::URL_PATTERN, 'x' * 23)
19 new_text.gsub!(Account::MENTION_RE, '@\2')
20 end
21 end
22 end
This page took 0.06968 seconds and 4 git commands to generate.