inexorabletash / polyfill

JavaScript Polyfills, Shims and More
Other
1.36k stars 354 forks source link

Fix isName regular expression #161

Closed jahson closed 3 years ago

jahson commented 3 years ago

Regular expression for header name was wrong, that caused headers like "P3P" to fail, because 3 was not in the set of accepted chars.

According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 the field name is defined as field name = token, the token is defined as token = 1*tchar, where tchar is

tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /"^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA

ALPHA is defined in https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1 as

ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z

and DIGIT is defined as

DIGIT          =  %x30-39 ; 0-9

isName regular expression was /^[!#$%&'*+\-.09A-Z^_`a-z|~]+$/ and with all above info the issue is easily spotted, because 0, and 9 should have - between them, and the regular expression should look like /^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/.

inexorabletash commented 3 years ago

Ooof, good catch. Looks like just a typo.