From e87b20b8e8d3795349758cd66912a9ad091bcd9c Mon Sep 17 00:00:00 2001 From: Jan Hrcek Date: Tue, 2 Jan 2018 07:46:09 +0100 Subject: [PATCH] URI encode strings in urls (#9) --- elm/Page.elm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/elm/Page.elm b/elm/Page.elm index f570d15..d88b568 100644 --- a/elm/Page.elm +++ b/elm/Page.elm @@ -6,8 +6,9 @@ module Page , toUrlHash ) +import Http import Navigation -import UrlParser exposing ((), Parser, map, oneOf, s, string) +import UrlParser exposing ((), Parser, custom, map, oneOf, s) type Page @@ -26,7 +27,7 @@ toUrlHash page = "#/summary" MethodDetails ( clz, method ) _ -> - "#/class/" ++ clz ++ "/method/" ++ method + "#/class/" ++ Http.encodeUri clz ++ "/method/" ++ Http.encodeUri method route : Parser (Page -> a) a @@ -35,10 +36,17 @@ route = [ map Summary (s "summary") , map (\clz method -> MethodDetails ( clz, method ) Nothing) - (s "class" string s "method" string) + (s "class" uriEncodedString s "method" uriEncodedString) ] +uriEncodedString : Parser (String -> a) a +uriEncodedString = + custom "URI_ENCODED_STRING" <| + \piece -> + Result.fromMaybe ("Failed to decode URI piece" ++ piece) (Http.decodeUri piece) + + parse : Navigation.Location -> Maybe Page parse location = UrlParser.parseHash route location