FEATURE: Improve errors when title is invalid (#11149)

It used to simply say "title is invalid" without giving any hint what
the problem could be. This commit adds different errors messages for
all caps titles, low entropy titles or titles with very long words.
This commit is contained in:
Bianca Nenciu
2020-11-11 15:11:36 +02:00
committed by GitHub
parent ab314218d3
commit a48f7ba61c
4 changed files with 46 additions and 19 deletions

View File

@ -54,12 +54,6 @@ class TextSentinel
seems_quiet?
end
private
def symbols_regex
/[\ -\/\[-\`\:-\@\{-\~]/m
end
def seems_meaningful?
# Minimum entropy if entropy check required
@opts[:min_entropy].blank? || (entropy >= @opts[:min_entropy])
@ -71,10 +65,6 @@ class TextSentinel
@text.gsub(symbols_regex, '').size > 0
end
def skipped_locale
%w(zh_CN zh_TW ko ja).freeze
end
def seems_unpretentious?
return true if skipped_locale.include?(SiteSetting.default_locale)
# Don't allow super long words if there is a word length maximum
@ -87,4 +77,14 @@ class TextSentinel
SiteSetting.allow_uppercase_posts || @text == @text.mb_chars.downcase.to_s || @text != @text.mb_chars.upcase.to_s
end
private
def symbols_regex
/[\ -\/\[-\`\:-\@\{-\~]/m
end
def skipped_locale
%w(zh_CN zh_TW ko ja).freeze
end
end