Skip to content

Commit 69f0ae9

Browse files
author
Marcin Szamotulski
committed
fix #37
1 parent 1c1aa3c commit 69f0ae9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Routing/Parser.purs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ module Routing.Parser (
22
parse
33
) where
44

5-
import Prelude (map, discard, (>>>), ($), (<<<), (==), (<*>), (<$>), (<=))
6-
import Routing.Types (Route, RoutePart(..))
75
import Data.Array as A
86
import Data.Map as M
97
import Data.String as S
108
import Control.MonadPlus (guard)
9+
import Data.Either (fromRight)
1110
import Data.List (fromFoldable, List)
1211
import Data.Maybe (Maybe, fromMaybe)
12+
import Data.String.Regex (regex, split) as R
13+
import Data.String.Regex.Flags (noFlags) as R
1314
import Data.Traversable (traverse)
1415
import Data.Tuple (Tuple(..))
16+
import Partial.Unsafe (unsafePartial)
17+
import Prelude (map, discard, (>>>), ($), (<<<), (==), (<*>), (<$>), (<=))
18+
import Routing.Types (Route, RoutePart(..))
1519

1620
-- | Parse part of hash. Will return `Query (Map String String)` for query
1721
-- | i.e. `"?foo=bar&bar=baz"` -->
@@ -36,4 +40,4 @@ parsePart str = fromMaybe (Path str) do
3640
-- | applied to every hash part (usually `decodeURIComponent`)
3741
parse :: (String -> String) -> String -> Route
3842
parse decoder hash =
39-
map ( decoder >>> parsePart ) $ fromFoldable (S.split (S.Pattern "/") hash)
43+
map ( decoder >>> parsePart ) $ fromFoldable (R.split (unsafePartial fromRight $ R.regex "\\/|(?=\\?)" R.noFlags) hash)

test/Test/Main.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ routing =
3939
main :: Eff (console :: CONSOLE) Unit
4040
main = do
4141
print "Foo: " $ match routing "foo/12/?welp='hi'&b=false" -- foo
42+
print "Foo: " $ match routing "foo/12?welp='hi'&b=false" -- foo
4243
print "Quux: " $ match routing "/quux/42" -- quux
4344
print "Baz: " $ match routing "/123/" -- baz
4445
print "End: " $ match routing "/1" -- end

0 commit comments

Comments
 (0)