aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/string_ext_test.rb
diff options
context:
space:
mode:
authorHenrik Nygren <nygrenh@gmail.com>2015-02-25 14:28:08 +0200
committerHenrik Nygren <nygrenh@gmail.com>2015-02-25 17:02:22 +0200
commitece0d25c2b64b1bc1f1b4b6343a7f5b909d75f06 (patch)
tree1ed3d4f01343bfe0d1193dabed024ce3bcd35290 /activesupport/test/core_ext/string_ext_test.rb
parent5a6868b6175167d91fcfaed82b4d4627281a4878 (diff)
downloadrails-ece0d25c2b64b1bc1f1b4b6343a7f5b909d75f06.tar.gz
rails-ece0d25c2b64b1bc1f1b4b6343a7f5b909d75f06.tar.bz2
rails-ece0d25c2b64b1bc1f1b4b6343a7f5b909d75f06.zip
Fix a backtracking problem in String#truncate_words
Fixes #19070.
Diffstat (limited to 'activesupport/test/core_ext/string_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 24037c665a..ac5a959409 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -249,6 +249,15 @@ class StringInflectionsTest < ActiveSupport::TestCase
assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :omission => "[...]", :separator => '<br>')
end
+ def test_truncate_words_with_complex_string
+ Timeout.timeout(10) do
+ complex_string = "aa aa aaa aa aaa aaa aaa aa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaaa aaaaa aaaaa aaaaaa aa aa aa aaa aa aaa aa aa aa aa a aaa aaa \n a aaa <<s"
+ assert_equal complex_string.truncate_words(80), complex_string
+ end
+ rescue Timeout::Error
+ assert false
+ end
+
def test_truncate_multibyte
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8),
"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8).truncate(10)