diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 1470243c..21bed3c5 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -6,7 +6,7 @@ require 'bigdecimal' module Liquid module StandardFilters - MAX_INT = (1 << 31) - 1 + MAX_I32 = (1 << 31) - 1 HTML_ESCAPE = { '&' => '&', '>' => '>', @@ -239,9 +239,9 @@ module Liquid wordlist = begin input.split(" ", words + 1) rescue RangeError - raise if words + 1 < MAX_INT - # e.g. integer #{words} too big to convert to `int' - raise Liquid::ArgumentError, "integer #{words} too big for truncatewords" + # integer too big for String#split, but we can semantically assume no truncation is needed + return input if words + 1 > MAX_I32 + raise # unexpected error end return input if wordlist.length <= words diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index 3b2cffa3..519a7f3f 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -227,10 +227,8 @@ class StandardFiltersTest < Minitest::Test assert_equal('one two three...', @filters.truncatewords("one two\tthree\nfour", 3)) assert_equal('one two...', @filters.truncatewords("one two three four", 2)) assert_equal('one...', @filters.truncatewords("one two three four", 0)) - exception = assert_raises(Liquid::ArgumentError) do - @filters.truncatewords("one two three four", 1 << 31) - end - assert_equal("Liquid error: integer #{1 << 31} too big for truncatewords", exception.message) + assert_equal('one two three four', @filters.truncatewords("one two three four", 1 << 31)) + assert_equal('one...', @filters.truncatewords("one two three four", -(1 << 32))) end def test_strip_html