From 1b17e299782b07fe837eb51ab10d0ab68cbf4c5e Mon Sep 17 00:00:00 2001 From: Alexander Ekdahl Date: Sat, 5 Oct 2019 16:58:24 -0400 Subject: [PATCH] Support IPv6 literal --- src/Url.elm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Url.elm b/src/Url.elm index 42c740e..ade279f 100644 --- a/src/Url.elm +++ b/src/Url.elm @@ -163,21 +163,30 @@ chompBeforePath : Protocol -> String -> Maybe String -> Maybe String -> String - chompBeforePath protocol path params frag str = if String.isEmpty str || String.contains "@" str then Nothing + else if String.startsWith "[" str then + -- IPv6 literal enclosed in brackets + case String.indexes "]" str of + i :: [] -> + Just <| Url protocol (String.left (i + 1) str) (String.toInt (String.dropLeft (i + 2) str)) path params frag + + _ -> + Nothing + else - case String.indexes ":" str of - [] -> - Just <| Url protocol str Nothing path params frag + case String.indexes ":" str of + [] -> + Just <| Url protocol str Nothing path params frag - i :: [] -> - case String.toInt (String.dropLeft (i + 1) str) of - Nothing -> - Nothing + i :: [] -> + case String.toInt (String.dropLeft (i + 1) str) of + Nothing -> + Nothing - port_ -> - Just <| Url protocol (String.left i str) port_ path params frag + port_ -> + Just <| Url protocol (String.left i str) port_ path params frag - _ -> - Nothing + _ -> + Nothing {-| Turn a [`Url`](#Url) into a `String`.