From cf86f274156bba4a205c65d3bdabf70717fbcb32 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Tue, 17 Nov 2015 12:27:44 -0800 Subject: [PATCH] FEATURE: New setting to allow all caps posts Adds a setting to ignore text_sentinel's check on all caps content. --- config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + lib/text_sentinel.rb | 2 +- spec/components/text_sentinel_spec.rb | 5 +++++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a6e3d0d9fef..df50a00c398 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1059,6 +1059,7 @@ en: title_max_word_length: "The maximum allowed word length, in characters, in a topic title." title_min_entropy: "The minimum entropy (unique characters, non-english count for more) required for a topic title." body_min_entropy: "The minimum entropy (unique characters, non-english count for more) required for a post body." + allow_uppercase_posts: "Allow all caps in a topic title or a post body." title_fancy_entities: "Convert common ASCII characters to fancy HTML entities in topic titles, ala SmartyPants http://daringfireball.net/projects/smartypants/" diff --git a/config/site_settings.yml b/config/site_settings.yml index d2f427f8804..e5583b231a7 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -377,6 +377,7 @@ posting: default: 255 max: 255 title_min_entropy: 10 + allow_uppercase_posts: false title_prettify: true title_fancy_entities: true min_private_message_title_length: diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb index 1210ad379b2..8e01a588813 100644 --- a/lib/text_sentinel.rb +++ b/lib/text_sentinel.rb @@ -73,7 +73,7 @@ class TextSentinel def seems_quiet? # We don't allow all upper case content in english - not((@text =~ /[A-Z]+/) && !(@text =~ /[^[:ascii:]]/) && (@text == @text.upcase)) + SiteSetting.allow_uppercase_posts || not((@text =~ /[A-Z]+/) && !(@text =~ /[^[:ascii:]]/) && (@text == @text.upcase)) end end diff --git a/spec/components/text_sentinel_spec.rb b/spec/components/text_sentinel_spec.rb index cd9e41d6678..c93df22aaf9 100644 --- a/spec/components/text_sentinel_spec.rb +++ b/spec/components/text_sentinel_spec.rb @@ -74,6 +74,11 @@ describe TextSentinel do expect(TextSentinel.new(valid_string.upcase)).not_to be_valid end + it "allows all caps topics when loud posts are allowed" do + SiteSetting.stubs(:allow_uppercase_posts).returns(true) + expect(TextSentinel.new(valid_string.upcase)).to be_valid + end + it "enforces the minimum entropy" do expect(TextSentinel.new(valid_string, min_entropy: 16)).to be_valid end