diff --git a/lib/elixir/lib/uri.ex b/lib/elixir/lib/uri.ex index 25a9edc88ad..420d3a7cdf0 100644 --- a/lib/elixir/lib/uri.ex +++ b/lib/elixir/lib/uri.ex @@ -484,18 +484,19 @@ defmodule URI do unpercent(string, "", true) end + defguardp is_hex(char) when char in ?0..?9 or char in ?A..?F or char in ?a..?f + defp unpercent(<>, acc, spaces = true) do unpercent(tail, <>, spaces) end + defp unpercent(<>, acc, spaces) + when is_hex(h1) and is_hex(h2) do + unpercent(tail, <>, spaces) + end + defp unpercent(<>, acc, spaces) do - with <> <- tail, - dec1 when is_integer(dec1) <- hex_to_dec(hex1), - dec2 when is_integer(dec2) <- hex_to_dec(hex2) do - unpercent(tail, <>, spaces) - else - _ -> unpercent(tail, <>, spaces) - end + unpercent(tail, <>, spaces) end defp unpercent(<>, acc, spaces) do @@ -508,7 +509,6 @@ defmodule URI do defp hex_to_dec(n) when n in ?A..?F, do: n - ?A + 10 defp hex_to_dec(n) when n in ?a..?f, do: n - ?a + 10 defp hex_to_dec(n) when n in ?0..?9, do: n - ?0 - defp hex_to_dec(_n), do: nil @doc """ Creates a new URI struct by parsing and validating a string or from an existing URI.