on master help sign in
Dropping initial question mark for query string
d2f1908Michael Snoyman
Network/Wai/Parse.hs+11−7
@@ -52,14 +52,18 @@ breakDiscard w s =
52-- * Percent decoding errors are ignored. In particular, "%Q" will be output as
52-- * Percent decoding errors are ignored. In particular, "%Q" will be output as
53-- "%Q".
53-- "%Q".
54parseQueryString :: S.ByteString -> [(S.ByteString, S.ByteString)]
54parseQueryString :: S.ByteString -> [(S.ByteString, S.ByteString)]
55−parseQueryString q | S.null q = []
55+parseQueryString = parseQueryString' . dropQuestion
56−parseQueryString q =
57− let (x, xs) = breakDiscard 38 q -- ampersand
58− in parsePair x : parseQueryString xs
59 where
56 where
60− parsePair x =
57+ dropQuestion q | S.null q || S.head q /= 63 = q
58+ dropQuestion q | otherwise = S.tail q
59+ parseQueryString' q | S.null q = []
60+ parseQueryString' q =
61+ let (x, xs) = breakDiscard 38 q -- ampersand
62+ in parsePair x : parseQueryString' xs
63+ where
64+ parsePair x =
61− let (k, v) = breakDiscard 61 x -- equal sign
65+ let (k, v) = breakDiscard 61 x -- equal sign
62− in (qsDecode k, qsDecode v)
66+ in (qsDecode k, qsDecode v)
63
67
64
68
65qsDecode :: S.ByteString -> S.ByteString
69qsDecode :: S.ByteString -> S.ByteString
runtests.hs+18
@@ -14,6 +14,7 @@ main = defaultMain [testSuite]
14testSuite :: Test
14testSuite :: Test
15testSuite = testGroup "Network.Wai.Parse"
15testSuite = testGroup "Network.Wai.Parse"
16 [ testCase "parseQueryString" caseParseQueryString
16 [ testCase "parseQueryString" caseParseQueryString
17+ , testCase "parseQueryString with question mark" caseParseQueryStringQM
17 , testCase "parseCookies" caseParseCookies
18 , testCase "parseCookies" caseParseCookies
18 , testCase "parseHttpAccept" caseParseHttpAccept
19 , testCase "parseHttpAccept" caseParseHttpAccept
19 , testCase "parseRequestBody" caseParseRequestBody
20 , testCase "parseRequestBody" caseParseRequestBody
@@ -37,6 +38,23 @@ caseParseQueryString = do
37 go [("/", "")] "%2f"
38 go [("/", "")] "%2f"
38 go [("foo bar", "")] "foo+bar"
39 go [("foo bar", "")] "foo+bar"
39
40
41+caseParseQueryStringQM :: Assertion
42+caseParseQueryStringQM = do
43+ let go l r =
44+ map (S8.pack *** S8.pack) l
45+ @=? parseQueryString (S8.pack $ '?' : r)
46+
47+ go [] ""
48+ go [("foo", "")] "foo"
49+ go [("foo", "bar")] "foo=bar"
50+ go [("foo", "bar"), ("baz", "bin")] "foo=bar&baz=bin"
51+ go [("%Q", "")] "%Q"
52+ go [("%1Q", "")] "%1Q"
53+ go [("%1", "")] "%1"
54+ go [("/", "")] "%2F"
55+ go [("/", "")] "%2f"
56+ go [("foo bar", "")] "foo+bar"
57+
40caseParseCookies :: Assertion
58caseParseCookies :: Assertion
41caseParseCookies = do
59caseParseCookies = do
42 let input = S8.pack "a=a1;b=b2; c=c3"
60 let input = S8.pack "a=a1;b=b2; c=c3"
wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
1Name: wai-extra
1Name: wai-extra
2−Version: 0.1.2
2+Version: 0.1.2.1
3Synopsis: Provides some basic WAI handlers and middleware.
3Synopsis: Provides some basic WAI handlers and middleware.
4Description: The goal here is to provide common features without many dependencies.
4Description: The goal here is to provide common features without many dependencies.
5License: BSD3
5License: BSD3