Merge pull request #172 from jeremybanks/master

Do not strip leading and trailing whitespace from raw posts
This commit is contained in:
Robin Ward
2013-02-19 08:15:39 -08:00
4 changed files with 45 additions and 16 deletions

View File

@@ -15,8 +15,8 @@ class TextSentinel
if text.present?
@text = text.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
@text.strip!
@text.gsub!(/ +/m, ' ') if @opts[:remove_interior_spaces]
@text.strip! if @opts[:strip]
end
end
@@ -24,19 +24,20 @@ class TextSentinel
TextSentinel.new(text,
min_entropy: SiteSetting.title_min_entropy,
max_word_length: SiteSetting.max_word_length,
remove_interior_spaces: true)
remove_interior_spaces: true,
strip: true)
end
# Entropy is a number of how many unique characters the string needs.
def entropy
return 0 if @text.blank?
@entropy ||= @text.each_char.to_a.uniq.size
@entropy ||= @text.strip.each_char.to_a.uniq.size
end
def valid?
# Blank strings are not valid
return false if @text.blank?
return false if @text.blank? || @text.strip.blank?
# Entropy check if required
return false if @opts[:min_entropy].present? and (entropy < @opts[:min_entropy])