diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 590340dce..3be892aad 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -45,6 +45,10 @@ def url_encode(input) CGI.escape(input) unless input.nil? end + def url_decode(input) + CGI.unescape(input) unless input.nil? + end + def slice(input, offset, length = nil) offset = Utils.to_integer(offset) length = length ? Utils.to_integer(length) : 1 diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index b91074bb7..a37e0af21 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -130,6 +130,13 @@ def test_url_encode assert_equal nil, @filters.url_encode(nil) end + def test_url_decode + assert_equal 'foo bar', @filters.url_decode('foo+bar') + assert_equal 'foo bar', @filters.url_decode('foo%20bar') + assert_equal 'foo+1@example.com', @filters.url_decode('foo%2B1%40example.com') + assert_equal nil, @filters.url_decode(nil) + end + def test_truncatewords assert_equal 'one two three', @filters.truncatewords('one two three', 4) assert_equal 'one two...', @filters.truncatewords('one two three', 2)