Skip to content

Commit 7b0773e

Browse files
authored
Merge pull request #47 from garyb/encoded-path-fix
Fix for URI-encoded path segments without query fragment
2 parents a258698 + 418058d commit 7b0773e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Routing/Parser.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ parse decoder hash =
3838
where
3939
pathParts str =
4040
let
41-
parts = L.fromFoldable $ map Path (S.split (S.Pattern "/") str)
41+
parts = L.fromFoldable $ map (Path <<< decoder) (S.split (S.Pattern "/") str)
4242
in
4343
case L.unsnoc parts of
4444
Just { init, last: Path "" } -> init

test/Test/Main.purs

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import Data.Map as M
1212
import Data.Tuple (Tuple(..))
1313
import Routing (match)
1414
import Routing.Match (Match, list)
15-
import Routing.Match.Class (bool, end, int, lit, num, param, params)
15+
import Routing.Match.Class (bool, end, int, lit, num, str, param, params)
1616
import Test.Assert (ASSERT, assert')
1717

1818
data FooBar
1919
= Foo Number (M.Map String String)
2020
| Bar Boolean String
2121
| Baz (List Number)
2222
| Quux Int
23+
| Corge String
2324
| End Int
2425

2526
derive instance eqFooBar :: Eq FooBar
@@ -29,13 +30,15 @@ instance showFooBar :: Show FooBar where
2930
show (Bar bool str) = "(Bar " <> show bool <> " " <> show str <> ")"
3031
show (Baz lst) = "(Baz " <> show lst <> ")"
3132
show (Quux i) = "(Quux " <> show i <> ")"
33+
show (Corge str) = "(Corge " <> show str <> ")"
3234
show (End i) = "(End " <> show i <> ")"
3335

3436
routing :: Match FooBar
3537
routing =
3638
Foo <$> (lit "foo" *> num) <*> params
3739
<|> Bar <$> (lit "bar" *> bool) <*> (param "baz")
3840
<|> Quux <$> (lit "" *> lit "quux" *> int)
41+
<|> Corge <$> (lit "corge" *> str)
3942
-- Order matters here. `list` is greedy, and `end` wont match after it
4043
<|> End <$> (lit "" *> int <* end)
4144
<|> Baz <$> (list num)
@@ -45,6 +48,10 @@ main :: Eff (assert :: ASSERT, console :: CONSOLE) Unit
4548
main = do
4649
assertEq (match routing "foo/12/?welp='hi'&b=false") (Right (Foo 12.0 (M.fromFoldable [Tuple "welp" "'hi'", Tuple "b" "false"])))
4750
assertEq (match routing "foo/12?welp='hi'&b=false") (Right (Foo 12.0 (M.fromFoldable [Tuple "welp" "'hi'", Tuple "b" "false"])))
51+
assertEq (match routing "bar/true?baz=test") (Right (Bar true "test"))
52+
assertEq (match routing "bar/false?baz=%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9%20%D1%84%D0%B0%D0%B9%D0%BB") (Right (Bar false "временный файл"))
53+
assertEq (match routing "corge/test") (Right (Corge "test"))
54+
assertEq (match routing "corge/%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9%20%D1%84%D0%B0%D0%B9%D0%BB") (Right (Corge "временный файл"))
4855
assertEq (match routing "/quux/42") (Right (Quux 42))
4956
assertEq (match routing "123/") (Right (Baz (L.fromFoldable [123.0])))
5057
assertEq (match routing "/1") (Right (End 1))

0 commit comments

Comments
 (0)