]> cat aescling's git repositories - mastodon.git/blob - app/validators/note_length_validator.rb
replace all instances of "ends_with?" with "end_with?" (#15745)
[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, I18n.t('statuses.over_character_limit', max: 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.091118 seconds and 5 git commands to generate.