From d740d7b25fde2facdce73037fbd72f8d37b8827f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 14 Feb 2013 16:09:57 -0500 Subject: [PATCH] Fix for foreign language titles: Only enforce upper case rule on english alphabet. --- lib/text_sentinel.rb | 4 ++-- spec/components/text_sentinel_spec.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb index b081396d4ab..61515929ad5 100644 --- a/lib/text_sentinel.rb +++ b/lib/text_sentinel.rb @@ -54,8 +54,8 @@ class TextSentinel return false if @opts[:max_word_length] and @text =~ /\w{#{@opts[:max_word_length]},}(\s|$)/ - # We don't allow all upper case content - return false if @text == @text.upcase + # We don't allow all upper case content in english + return false if (@text =~ /[A-Z]+/) and (@text == @text.upcase) true end diff --git a/spec/components/text_sentinel_spec.rb b/spec/components/text_sentinel_spec.rb index 7467395145a..2b50aef8384 100644 --- a/spec/components/text_sentinel_spec.rb +++ b/spec/components/text_sentinel_spec.rb @@ -30,6 +30,10 @@ describe TextSentinel do TextSentinel.new("evil trout is evil").entropy.should == 10 end + it "Works on foreign characters" do + TextSentinel.new("去年十社會警告").entropy.should == 7 + end + end context "cleaning up" do @@ -78,9 +82,12 @@ describe TextSentinel do TextSentinel.new(valid_string, min_entropy: 17).should_not be_valid end + it "allows all foreign characters" do + TextSentinel.new("去年十二月,北韓不顧國際社會警告").should be_valid + end + it "doesn't allow a long alphanumeric string with no spaces" do - TextSentinel.new("jfewjfoejwfojeojfoejofjeo38493824jfkjewfjeoifijeoijfoejofjeojfoewjfo834988394032jfiejoijofijeojfeojfojeofjewojfojeofjeowjfojeofjeojfoe3898439849032jfeijfwoijfoiewj", - max_word_length: 30).should_not be_valid + TextSentinel.new("jfewjfoejwfojeojfoejofjeo3" * 5, max_word_length: 30).should_not be_valid end it "doesn't except junk symbols as a string" do