mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #172 from jeremybanks/master
Do not strip leading and trailing whitespace from raw posts
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user