Skip to content

Commit

Permalink
passing empty params test
Browse files Browse the repository at this point in the history
  • Loading branch information
et1975 committed Dec 26, 2022
1 parent 014ab69 commit 7ea99b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ let internal toKeyValuePair (segment: string) =
#endif

let parseParams (querystring: string) =
querystring.Substring(1).Split('&')
|> Seq.map toKeyValuePair
|> Seq.choose id
|> Map.ofSeq
if System.String.IsNullOrEmpty querystring then Map.empty
else
querystring.Split('&')
|> Seq.map toKeyValuePair
|> Seq.choose id
|> Map.ofSeq

(**
#### Parsers
Expand All @@ -367,7 +369,7 @@ let parseUrl (parser: Parser<_,_>) (url:string) =
let pos = url.IndexOf "?"
if pos >= 0 then
let path = url.Substring(0,pos)
let search = url.Substring(pos)
let search = url.Substring(pos+1)
parse parser path (parseParams search)
else
parse parser url Map.empty
5 changes: 5 additions & 0 deletions tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type Routes =
let curry3 f a b c = f (a,b,c)

open NUnit.Framework
[<Test>]
let ``empty query string`` () =
let parser = s "id" </> i32 <?> stringParam "one" <?> stringParam "two" |> map (curry3 IntAndTwoStringOptions)
parseUrl parser "id/123?" =! Some (IntAndTwoStringOptions (123, None, None))

[<Test>]
let ``parses subroute and multiple params`` () =
let parser = s "id" </> i32 <?> stringParam "one" <?> stringParam "two" |> map (curry3 IntAndTwoStringOptions)
Expand Down

0 comments on commit 7ea99b5

Please sign in to comment.