Skip to content

Commit 7bd5eec

Browse files
committed
lpeg_patterns/http: Allow OWS between STS directives
1 parent b124aa0 commit 7bd5eec

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lpeg_patterns/http.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ _M.Sec_WebSocket_Version_Server = comma_sep(version)
420420
-- RFC 6797
421421
local directive_name = _M.token / string.lower
422422
local directive_value = _M.token + _M.quoted_string
423-
local directive = Cg(directive_name * ((P"=" * directive_value) + Cc(true)))
423+
local directive = Cg(directive_name * ((_M.OWS * P"=" * _M.OWS * directive_value) + Cc(true)))
424424
_M.Strict_Transport_Security = directive^-1 * (_M.OWS * P";" * _M.OWS * directive^-1)^0
425425

426426
-- RFC 7089

spec/http_spec.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,12 @@ describe("http patterns", function()
201201
assert.same({"foo", {filename="example"}}, Content_Disposition:match"foo; filename=example")
202202
assert.same({"foo", {filename="example"}}, Content_Disposition:match"foo; filename*=UTF-8''example")
203203
end)
204+
it("Parses a Strict-Transport-Security header", function()
205+
local sts_patt = lpeg.Cf(lpeg.Ct(true) * http.Strict_Transport_Security, rawset) * EOF
206+
assert.same({["max-age"] = "0"}, sts_patt:match("max-age=0"))
207+
assert.same({["max-age"] = "0"}, sts_patt:match("max-age = 0"))
208+
assert.same({["max-age"] = "0"}, sts_patt:match("Max-Age=0"))
209+
assert.same({["max-age"] = "0"; includesubdomains = true}, sts_patt:match("max-age=0;includeSubdomains"))
210+
assert.same({["max-age"] = "0"; includesubdomains = true}, sts_patt:match("max-age=0 ; includeSubdomains"))
211+
end)
204212
end)

0 commit comments

Comments
 (0)