Skip to content

Commit

Permalink
Fix for foreign language titles: Only enforce upper case rule on engl…
Browse files Browse the repository at this point in the history
…ish alphabet.
  • Loading branch information
eviltrout committed Feb 14, 2013
1 parent b945719 commit d740d7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/text_sentinel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def valid?

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
Expand Down
11 changes: 9 additions & 2 deletions spec/components/text_sentinel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
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
Expand Down Expand Up @@ -78,9 +82,12 @@
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
Expand Down

0 comments on commit d740d7b

Please sign in to comment.