FIX: Unicode aware text sentinel (#4301)

* FIX: Handle unicode text on Text Sentinel

Uses active_support to properly handle unicode text

* Adds test cases to unicode Text Sentinel
This commit is contained in:
Rafael dos Santos Silva
2016-07-12 12:08:55 -03:00
committed by Robin Ward
parent 166d753bd3
commit 5915929166
2 changed files with 11 additions and 3 deletions

View File

@@ -1,3 +1,7 @@
# Whe use ActiveSupport mb_chars from here to properly support non ascii downcase
# TODO remove when ruby 2.4 lands
require 'active_support/core_ext/string/multibyte'
#
# Given a string, tell us whether or not is acceptable.
#
@@ -72,8 +76,8 @@ class TextSentinel
def seems_quiet?
# We don't allow all upper case content in english
SiteSetting.allow_uppercase_posts || not((@text =~ /[A-Z]+/) && !(@text =~ /[^[:ascii:]]/) && (@text == @text.upcase))
# 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
end
end