Skip to content

A platform for community discussion. Free, open, simple.

FIX: prevents exception when text input is nil (#12922)

Joffrey JAFFEUXd16a39dc5331
diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb
index 72053574fb6..f720e1b5032 100644
--- a/lib/text_sentinel.rb
+++ b/lib/text_sentinel.rb
@@ -68,7 +68,9 @@ class TextSentinel
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
- @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 || 0) <= @opts[:max_word_length]
end
def seems_quiet?
diff --git a/spec/components/text_sentinel_spec.rb b/spec/components/text_sentinel_spec.rb
index d14a8bf6248..2676a010134 100644
--- a/spec/components/text_sentinel_spec.rb
+++ b/spec/components/text_sentinel_spec.rb
@@ -61,6 +61,18 @@ describe TextSentinel do
end
end
+ it "uses a sensible min entropy value when min body length is less than min entropy" do
+ SiteSetting.min_post_length = 3
+ SiteSetting.body_min_entropy = 7
+ expect(TextSentinel.body_sentinel('Yup')).to be_valid
+ end
+
+ it "uses a sensible min entropy value when min pm body length is less than min entropy" do
+ SiteSetting.min_post_length = 5
+ SiteSetting.min_personal_message_post_length = 3
+ SiteSetting.body_min_entropy = 7
+ expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid
+ end
end
context "validity" do
@@ -144,19 +156,9 @@ describe TextSentinel do
end
- context 'body_sentinel' do
-
- it "uses a sensible min entropy value when min body length is less than min entropy" do
- SiteSetting.min_post_length = 3
- SiteSetting.body_min_entropy = 7
- expect(TextSentinel.body_sentinel('Yup')).to be_valid
- end
-
- it "uses a sensible min entropy value when min pm body length is less than min entropy" do
- SiteSetting.min_post_length = 5
- SiteSetting.min_personal_message_post_length = 3
- SiteSetting.body_min_entropy = 7
- expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid
+ context 'seems_unpretentious?' do
+ it 'works with nil title' do
+ expect(TextSentinel.title_sentinel(nil).seems_unpretentious?).to eq(true)
end
end