Skip to content

Commit ffbcf67

Browse files
author
Gustavo Brunoro
committed
handling IPv6 addresses on URIs
* very naïve and permissive regex to check for IPv6 addreses.
1 parent d88cd5c commit ffbcf67

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/elixir/lib/uri.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,17 @@ defmodule URI do
189189
]
190190
end
191191

192+
defp has_ipv6_addr?(s), do: Regex.match?(%r/\[[0-9a-zA-Z:]*\]/, s)
192193
# Split an authority into its userinfo, host and port parts.
193194
defp split_authority(s) do
194195
s = s || ""
195-
components = Regex.run %r/(^(.*)@)?([^:]*)(:(\d*))?/, s
196+
components_regex = if has_ipv6_addr?(s) do
197+
%r/(^(.*)@)?\[([a-zA-Z0-9:]*)\](:(\d*))?/
198+
else
199+
%r/(^(.*)@)?([^:]*)(:(\d*))?/
200+
end
201+
202+
components = Regex.run components_regex, s
196203
destructure [_, _, userinfo, host, _, port], nillify(components)
197204
port = if port, do: binary_to_integer(port)
198205
{ userinfo, host, port }

0 commit comments

Comments
 (0)