Skip to content

Commit 6e1ae03

Browse files
committed
lpeg_patterns/http: Fix trailing whitespace of cookie pair
1 parent 7bd5eec commit 6e1ae03

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lpeg_patterns/http.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ do -- RFC 6265
365365
* _M.BWS * P"=" * _M.BWS * C(ext_char^0)
366366
+ (ext_char)^0 / string.lower * Cc(true)
367367
local cookie_av = extension_av
368-
local set_cookie_string = cookie_pair * Cf(Ct(true) * (P";" * _M.OWS * Cg(cookie_av) * _M.OWS)^0, rawset)
368+
local set_cookie_string = cookie_pair * Cf(Ct(true) * (P";" * _M.OWS * Cg(cookie_av))^0, rawset)
369369
_M.Set_Cookie = set_cookie_string
370370

371371
local cookie_string = Cf(Ct(true) * Cg(cookie_pair) * (P";" * _M.OWS * Cg(cookie_pair))^0, rawset)

spec/http_spec.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ describe("http patterns", function()
175175
it("Parses a Set-Cookie header", function()
176176
local Set_Cookie = lpeg.Ct(http.Set_Cookie) * EOF
177177
assert.same({"SID", "31d4d96e407aad42", {}}, Set_Cookie:match"SID=31d4d96e407aad42")
178+
assert.same({"SID", "", {}}, Set_Cookie:match"SID=")
178179
assert.same({"SID", "31d4d96e407aad42", {path="/"; domain="example.com"}}, Set_Cookie:match"SID=31d4d96e407aad42; Path=/; Domain=example.com")
179180
assert.same({"SID", "31d4d96e407aad42", {
180181
path = "/";
@@ -187,15 +188,16 @@ describe("http patterns", function()
187188
-- Quoted cookie value
188189
assert.same({"SID", "31d4d96e407aad42", {path = "/";}}, Set_Cookie:match[[SID="31d4d96e407aad42"; Path=/]])
189190
-- Crazy whitespace
190-
assert.same({"SID", "31d4d96e407aad42", {path = "/";}}, Set_Cookie:match"SID = 31d4d96e407aad42 ; Path = / ")
191-
assert.same({"SID", "31d4d96e407aad42", {["foo bar"] = true;}}, Set_Cookie:match"SID = 31d4d96e407aad42 ; foo bar ")
191+
assert.same({"SID", "31d4d96e407aad42", {path = "/";}}, Set_Cookie:match"SID = 31d4d96e407aad42 ; Path = /")
192+
assert.same({"SID", "31d4d96e407aad42", {["foo bar"] = true;}}, Set_Cookie:match"SID = 31d4d96e407aad42 ; foo bar")
192193
end)
193194
it("Parses a Cookie header", function()
194195
local Cookie = http.Cookie * EOF
195196
assert.same({SID = "31d4d96e407aad42"}, Cookie:match"SID=31d4d96e407aad42")
197+
assert.same({SID = "31d4d96e407aad42"}, Cookie:match"SID = 31d4d96e407aad42")
196198
assert.same({SID = "31d4d96e407aad42", lang = "en-US"}, Cookie:match"SID=31d4d96e407aad42; lang=en-US")
197199
end)
198-
it("Parses a Content_Disposition header", function()
200+
it("Parses a Content-Disposition header", function()
199201
local Content_Disposition = lpeg.Ct(http.Content_Disposition) * EOF
200202
assert.same({"foo", {}}, Content_Disposition:match"foo")
201203
assert.same({"foo", {filename="example"}}, Content_Disposition:match"foo; filename=example")

0 commit comments

Comments
 (0)