diff --git a/lib/liquid/filters.ex b/lib/liquid/filters.ex index a07b9321..7e3c353b 100644 --- a/lib/liquid/filters.ex +++ b/lib/liquid/filters.ex @@ -418,6 +418,12 @@ defmodule Liquid.Filters do def url_encode(nil), do: nil + def url_decode(input) when is_binary(input) do + input |> URI.decode_www_form() + end + + def url_decode(nil), do: nil + def date(input, format \\ "%F %T") def date(nil, _), do: nil diff --git a/test/liquid/filter_test.exs b/test/liquid/filter_test.exs index e52dd561..4e7f4476 100644 --- a/test/liquid/filter_test.exs +++ b/test/liquid/filter_test.exs @@ -119,6 +119,11 @@ defmodule Liquid.FilterTest do assert nil == Functions.url_encode(nil) end + test :url_decode do + assert "foo+1@example.com" == Functions.url_decode("foo%2B1%40example.com") + assert nil == Functions.url_decode(nil) + end + test :truncatewords do assert "one two three" == Functions.truncatewords("one two three", 4) assert "one two..." == Functions.truncatewords("one two three", 2)