diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 90dfdd3a..50f2dc40 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -76,7 +76,7 @@ module Liquid words = Utils.to_integer(words) l = words - 1 l = 0 if l < 0 - wordlist.length > l ? wordlist[0..l].join(" ".freeze) + truncate_string : input + wordlist.length > l ? wordlist[0..l].join(" ".freeze) + truncate_string.to_s : input end # Split input string into an array of substrings separated by given pattern. diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index a20e1c39..909ad443 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -154,6 +154,7 @@ class StandardFiltersTest < Minitest::Test assert_equal 'one two three', @filters.truncatewords('one two three') assert_equal 'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...', @filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15) assert_equal "测试测试测试测试", @filters.truncatewords('测试测试测试测试', 5) + assert_equal 'one two1', @filters.truncatewords("one two three", 2, 1) end def test_strip_html