FIX: Don't count HTML comments when calculating reply length. (#11658)

We'll remove them when we sanitize the post raw content.
This commit is contained in:
Roman Rizzi
2021-01-07 15:44:17 -03:00
committed by GitHub
parent 2e3b3ec2de
commit e696cba071
4 changed files with 41 additions and 2 deletions

View File

@@ -2,8 +2,11 @@
class StrippedLengthValidator < ActiveModel::EachValidator
def self.validate(record, attribute, value, range)
unless value.nil?
stripped_length = value.strip.length
if !value.nil?
html_comments_regexp = /<!--(.*?)-->/
stripped_length = value.gsub(html_comments_regexp, '')
stripped_length = stripped_length.strip.length
record.errors.add attribute, (I18n.t('errors.messages.too_short', count: range.begin)) unless
stripped_length >= range.begin
record.errors.add attribute, (I18n.t('errors.messages.too_long_validation', max: range.end, length: stripped_length)) unless