cookie 0.4.6 → 0.5.0
raw patch · 4 files changed
+36/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +8/−0
- Web/Cookie.hs +11/−2
- cookie.cabal +1/−1
- test/Spec.hs +16/−0
ChangeLog.md view
@@ -1,3 +1,11 @@+## 0.5.0++* Remove surrounding double quotes from cookie values when parsing [#31](https://github.com/snoyberg/cookie/pull/31)++ This is a breaking change, as it changes the behavior of `parseCookies` and `parseSetCookie` to no+ longer include the surrounding double quotes in the cookie value. This is the correct behavior+ according to the RFC.+ ## 0.4.6 * Resolve redundant import of Data.Monoid [#26](https://github.com/snoyberg/cookie/pull/26)
Web/Cookie.hs view
@@ -85,13 +85,22 @@ parseCookie s = let (key, value) = breakDiscard 61 s -- equals sign key' = S.dropWhile (== 32) key -- space- in (key', value)+ value' = dropEnds 34 value -- double quote+ in (key', value') breakDiscard :: Word8 -> S.ByteString -> (S.ByteString, S.ByteString) breakDiscard w s = let (x, y) = S.break (== w) s in (x, S.drop 1 y) +dropEnds :: Word8 -> S.ByteString -> S.ByteString+dropEnds w s =+ case S.unsnoc s of+ Just (s', w') | w' == w -> case S.uncons s' of+ Just (w'', s'') | w'' == w -> s''+ _ -> s+ _ -> s+ type CookieBuilder = (Builder, Builder) renderCookiesBuilder :: [CookieBuilder] -> Builder@@ -240,7 +249,7 @@ parseSetCookie :: S.ByteString -> SetCookie parseSetCookie a = SetCookie { setCookieName = name- , setCookieValue = value+ , setCookieValue = dropEnds 34 value -- double quote , setCookiePath = lookup "path" flags , setCookieExpires = lookup "expires" flags >>= parseCookieExpires
cookie.cabal view
@@ -1,5 +1,5 @@ name: cookie-version: 0.4.6+version: 0.5.0 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>
test/Spec.hs view
@@ -22,6 +22,8 @@ , testProperty "parse/render SetCookie" propParseRenderSetCookie , testProperty "parse/render cookies text" propParseRenderCookiesText , testCase "parseCookies" caseParseCookies+ , testCase "parseQuotedCookies" caseParseQuotedCookies+ , testCase "parseQuotedSetCookie" caseParseQuotedSetCookie , twoDigit 24 2024 , twoDigit 69 2069 , twoDigit 70 1970@@ -106,3 +108,17 @@ , show x , " 04:52:08 GMT" ]++caseParseQuotedCookies :: Assertion+caseParseQuotedCookies = do+ let input = S8.pack "a=\"a1\";b=\"b2\"; c=\"c3\""+ expected = [("a", "a1"), ("b", "b2"), ("c", "c3")]+ map (S8.pack *** S8.pack) expected @=? parseCookies input++caseParseQuotedSetCookie :: Assertion+caseParseQuotedSetCookie = do+ let input = S8.pack "a=\"a1\""+ result = parseSetCookie input+ resultNameAndValue = (setCookieName result, setCookieValue result)+ expected = (S8.pack "a", S8.pack "a1")+ expected @=? resultNameAndValue