From a95eac709a8b85d1743ff64692c779d8b9f3701c Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Mon, 12 Aug 2019 19:09:43 +0200 Subject: [PATCH] Fail on empty path elements --- frontend/src/Parse.elm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/Parse.elm b/frontend/src/Parse.elm index c8f927b..9fcfc39 100644 --- a/frontend/src/Parse.elm +++ b/frontend/src/Parse.elm @@ -1,16 +1,17 @@ module Parse exposing (parseUrl) import Data exposing (Provider(..), Url, pathSeparator) +import Maybe.Extra parseUrl : String -> Maybe Url parseUrl url = stripProtocol url |> splitProvider - |> Maybe.andThen splitOffHead - |> Maybe.andThen splitOffHead - |> Maybe.andThen splitOffHead - |> Maybe.andThen splitOffHead + |> Maybe.andThen filteredSplit + |> Maybe.andThen filteredSplit + |> Maybe.andThen filteredSplit + |> Maybe.andThen filteredSplit |> Maybe.andThen (\( ( ( ( ( prov, user ), repo ), separator ), gitref ), file ) -> if @@ -30,9 +31,15 @@ parseUrl url = ) -splitOffHead : ( a, List b ) -> Maybe ( ( a, b ), List b ) -splitOffHead ( head, tail ) = +filteredSplit : ( a, List String ) -> Maybe ( ( a, String ), List String ) +filteredSplit = + splitOffHead (\s -> not (String.isEmpty s)) + + +splitOffHead : (b -> Bool) -> ( a, List b ) -> Maybe ( ( a, b ), List b ) +splitOffHead pred ( head, tail ) = splitPart tail + |> Maybe.Extra.filter (\( h, _ ) -> pred h) |> Maybe.map (\( h, t ) -> ( ( head, h ), t ))