mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
If min entropy setting is greater than min post/body length setting, then use a sensible min entropy value instead
This commit is contained in:
@ -5,6 +5,8 @@ class TextSentinel
|
||||
|
||||
attr_accessor :text
|
||||
|
||||
ENTROPY_SCALE = 0.7
|
||||
|
||||
def initialize(text, opts=nil)
|
||||
@opts = opts || {}
|
||||
@text = text.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
|
||||
@ -15,14 +17,20 @@ class TextSentinel
|
||||
if opts[:private_message]
|
||||
scale_entropy = SiteSetting.min_private_message_post_length.to_f / SiteSetting.min_post_length.to_f
|
||||
entropy = (entropy * scale_entropy).to_i
|
||||
entropy = (SiteSetting.min_private_message_post_length.to_f * ENTROPY_SCALE).to_i if entropy > SiteSetting.min_private_message_post_length
|
||||
else
|
||||
entropy = (SiteSetting.min_post_length.to_f * ENTROPY_SCALE).to_i if entropy > SiteSetting.min_post_length
|
||||
end
|
||||
TextSentinel.new(text, min_entropy: entropy)
|
||||
end
|
||||
|
||||
def self.title_sentinel(text)
|
||||
TextSentinel.new(text,
|
||||
min_entropy: SiteSetting.title_min_entropy,
|
||||
max_word_length: SiteSetting.max_word_length)
|
||||
entropy = if SiteSetting.min_topic_title_length > SiteSetting.title_min_entropy
|
||||
SiteSetting.title_min_entropy
|
||||
else
|
||||
(SiteSetting.min_topic_title_length.to_f * ENTROPY_SCALE).to_i
|
||||
end
|
||||
TextSentinel.new(text, min_entropy: entropy, max_word_length: SiteSetting.max_word_length)
|
||||
end
|
||||
|
||||
# Entropy is a number of how many unique characters the string needs.
|
||||
|
Reference in New Issue
Block a user