Max Chars set via env
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (push) Blocked by required conditions
Ruby Testing / End to End testing (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (push) Blocked by required conditions
Ruby Testing / Back to original and return test (push) Blocked by required conditions
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (push) Blocked by required conditions
Ruby Testing / End to End testing (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (push) Blocked by required conditions
Ruby Testing / Back to original and return test (push) Blocked by required conditions
This commit is contained in:
parent
bb7024bf3f
commit
1f8b3fcc92
1 changed files with 4 additions and 7 deletions
|
@ -1,23 +1,20 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class StatusLengthValidator < ActiveModel::Validator
|
class StatusLengthValidator < ActiveModel::Validator
|
||||||
|
MAX_CHARS = (ENV['MAX_CHARS'] || 500).to_i
|
||||||
URL_PLACEHOLDER_CHARS = 23
|
URL_PLACEHOLDER_CHARS = 23
|
||||||
URL_PLACEHOLDER = 'x' * 23
|
URL_PLACEHOLDER = 'x' * 23
|
||||||
|
|
||||||
def max_chars
|
|
||||||
@max_chars ||= ENV.fetch('MAX_CHARACTERS', 500).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate(status)
|
def validate(status)
|
||||||
return unless status.local? && !status.reblog?
|
return unless status.local? && !status.reblog?
|
||||||
|
|
||||||
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: max_chars)) if too_long?(status)
|
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if too_long?(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def too_long?(status)
|
def too_long?(status)
|
||||||
countable_length(combined_text(status)) > max_chars
|
countable_length(combined_text(status)) > MAX_CHARS
|
||||||
end
|
end
|
||||||
|
|
||||||
def countable_length(str)
|
def countable_length(str)
|
||||||
|
@ -59,4 +56,4 @@ class StatusLengthValidator < ActiveModel::Validator
|
||||||
result << str[last_index..]
|
result << str[last_index..]
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue