mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 22:02:42 +08:00
FIX: skip some checks for CJK locale in TextSentinel (#7322)
This commit is contained in:
@ -69,12 +69,18 @@ class TextSentinel
|
|||||||
@text.gsub(symbols_regex, '').size > 0
|
@text.gsub(symbols_regex, '').size > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def skipped_locale
|
||||||
|
%w(zh_CN zh_TW ko ja).freeze
|
||||||
|
end
|
||||||
|
|
||||||
def seems_unpretentious?
|
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
|
# Don't allow super long words if there is a word length maximum
|
||||||
@opts[:max_word_length].blank? || @text.split(/\s|\/|-|\.|:/).map(&:size).max <= @opts[:max_word_length]
|
@opts[:max_word_length].blank? || @text.split(/\s|\/|-|\.|:/).map(&:size).max <= @opts[:max_word_length]
|
||||||
end
|
end
|
||||||
|
|
||||||
def seems_quiet?
|
def seems_quiet?
|
||||||
|
return true if skipped_locale.include?(SiteSetting.default_locale)
|
||||||
# We don't allow all upper case content
|
# We don't allow all upper case content
|
||||||
SiteSetting.allow_uppercase_posts || @text == @text.mb_chars.downcase.to_s || @text != @text.mb_chars.upcase.to_s
|
SiteSetting.allow_uppercase_posts || @text == @text.mb_chars.downcase.to_s || @text != @text.mb_chars.upcase.to_s
|
||||||
end
|
end
|
||||||
|
@ -95,6 +95,16 @@ describe TextSentinel do
|
|||||||
expect(TextSentinel.new("去年十二月,北韓不顧國際社會警告")).to be_valid
|
expect(TextSentinel.new("去年十二月,北韓不顧國際社會警告")).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "skips uppercase text for CJK locale" do
|
||||||
|
SiteSetting.default_locale = 'zh_CN'
|
||||||
|
expect(TextSentinel.new("去年SHIER月,北韓不顧國際社會警告")).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "skips long words check (`seems_unpretentious`) for CJK locale" do
|
||||||
|
SiteSetting.default_locale = 'zh_CN'
|
||||||
|
expect(TextSentinel.title_sentinel("非常长的文字没有空格分割肯定会触发警告但这不应该是一个错误这个要超过五十个个字符" * 2)).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it "doesn't allow a long alphanumeric string with no spaces" do
|
it "doesn't allow a long alphanumeric string with no spaces" do
|
||||||
expect(TextSentinel.new("jfewjfoejwfojeojfoejofjeo3" * 5, max_word_length: 30)).not_to be_valid
|
expect(TextSentinel.new("jfewjfoejwfojeojfoejofjeo3" * 5, max_word_length: 30)).not_to be_valid
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user