Fail on empty path elements
This commit is contained in:
parent
fcd9b963ff
commit
a95eac709a
@ -1,16 +1,17 @@
|
|||||||
module Parse exposing (parseUrl)
|
module Parse exposing (parseUrl)
|
||||||
|
|
||||||
import Data exposing (Provider(..), Url, pathSeparator)
|
import Data exposing (Provider(..), Url, pathSeparator)
|
||||||
|
import Maybe.Extra
|
||||||
|
|
||||||
|
|
||||||
parseUrl : String -> Maybe Url
|
parseUrl : String -> Maybe Url
|
||||||
parseUrl url =
|
parseUrl url =
|
||||||
stripProtocol url
|
stripProtocol url
|
||||||
|> splitProvider
|
|> splitProvider
|
||||||
|> Maybe.andThen splitOffHead
|
|> Maybe.andThen filteredSplit
|
||||||
|> Maybe.andThen splitOffHead
|
|> Maybe.andThen filteredSplit
|
||||||
|> Maybe.andThen splitOffHead
|
|> Maybe.andThen filteredSplit
|
||||||
|> Maybe.andThen splitOffHead
|
|> Maybe.andThen filteredSplit
|
||||||
|> Maybe.andThen
|
|> Maybe.andThen
|
||||||
(\( ( ( ( ( prov, user ), repo ), separator ), gitref ), file ) ->
|
(\( ( ( ( ( prov, user ), repo ), separator ), gitref ), file ) ->
|
||||||
if
|
if
|
||||||
@ -30,9 +31,15 @@ parseUrl url =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
splitOffHead : ( a, List b ) -> Maybe ( ( a, b ), List b )
|
filteredSplit : ( a, List String ) -> Maybe ( ( a, String ), List String )
|
||||||
splitOffHead ( head, tail ) =
|
filteredSplit =
|
||||||
|
splitOffHead (\s -> not (String.isEmpty s))
|
||||||
|
|
||||||
|
|
||||||
|
splitOffHead : (b -> Bool) -> ( a, List b ) -> Maybe ( ( a, b ), List b )
|
||||||
|
splitOffHead pred ( head, tail ) =
|
||||||
splitPart tail
|
splitPart tail
|
||||||
|
|> Maybe.Extra.filter (\( h, _ ) -> pred h)
|
||||||
|> Maybe.map (\( h, t ) -> ( ( head, h ), t ))
|
|> Maybe.map (\( h, t ) -> ( ( head, h ), t ))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user