From 31f60f094782d1dad1ff9a1ab417baa0958ea973 Mon Sep 17 00:00:00 2001 From: Jason Torres Date: Wed, 5 Dec 2018 08:54:47 +1100 Subject: [PATCH] Adds support for url_decode --- lib/liquid/filters.ex | 6 ++++++ test/liquid/filter_test.exs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/liquid/filters.ex b/lib/liquid/filters.ex index 9213a8ec..5009edfc 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)