on master help sign in
Support + in query strings
commitb604d8d7c65ead8f0321133420734cdc5f3b70bc authorMichael Snoyman <michael@snoyman.com> dateTue 18 May 2010, 13:20 (16 years ago) parent4c400b9
2 files changed+12−15
Network/Wai/Parse.hs+11−15 runtests.hs+1
Network/Wai/Parse.hs+11−15
@@ -9,18 +9,6 @@ import qualified Data.ByteString as S
99import Data.Word (Word8)
1010import Data.Bits
1111
12−c2w :: Char -> Word8
13−c2w = toEnum . fromEnum
14−
15−wequal :: Word8
16−wequal = c2w '='
17−
18−wand :: Word8
19−wand = c2w '&'
20−
21−wpercent :: Word8
22−wpercent = c2w '%'
23−
2412type BufferedBS = ([Word8], S.ByteString)
2513
2614uncons :: BufferedBS -> Maybe (Word8, BufferedBS)
@@ -66,9 +54,10 @@ parseQueryString q =
6654 (OneChar (w, _), Nothing) ->
6755 Just (wpercent, (NoPercent, cons w x))
6856 (NoPercent, Just (w, ws)) ->
69− if w == wpercent
70− then go (NoChar, ws)
71− else Just (w, (NoPercent, ws))
57+ if w == wpercent then go (NoChar, ws)
58+ else if w == wplus
59+ then Just (wspace, (NoPercent, ws))
60+ else Just (w, (NoPercent, ws))
7261 (NoChar, Just (w, ws)) ->
7362 case hexVal w of
7463 Nothing -> Just (wpercent, (NoPercent, x))
@@ -78,12 +67,19 @@ parseQueryString q =
7867 Nothing ->
7968 Just (wpercent, (NoPercent, w1 `cons` x))
8069 Just v2 -> Just (combine v1 v2, (NoPercent, ws))
70+ c2w :: Char -> Word8
71+ c2w = toEnum . fromEnum
72+ wequal = c2w '='
73+ wand = c2w '&'
74+ wpercent = c2w '%'
8175 w0 = c2w '0'
8276 w9 = c2w '9'
8377 wa = c2w 'a'
8478 wf = c2w 'f'
8579 wA = c2w 'A'
8680 wF = c2w 'F'
81+ wspace = c2w ' '
82+ wplus = c2w '+'
8783 hexVal w
8884 | w0 <= w && w <= w9 = Just $ w - w0
8985 | wa <= w && w <= wf = Just $ w - wa + 10
runtests.hs+1
@@ -28,3 +28,4 @@ caseParseQueryString = do
2828 go [("%1", "")] "%1"
2929 go [("/", "")] "%2F"
3030 go [("/", "")] "%2f"
31+ go [("foo bar", "")] "foo+bar"