Skip to content

Commit

Permalink
URI encode strings in urls (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Hrcek committed Jan 2, 2018
1 parent f138698 commit e87b20b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions elm/Page.elm
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit e87b20b

Please sign in to comment.