Adds support for `HTAB` as well as `SP` as whitespace separators in `content-type` headers
Fixes issue #52. Notes:
-
The fix applies to both
typeisandtypeis.is, instead of justtypeis.This is because
typeis.iscan receive a req-like or res-like object (this behaviour is undocumented but tested). I wanted to avoid situations wheretypeis(req, ...)would work buttypeis.is(req, ...)would not. -
The fix breaks backward compatibility in that, previously,
typeiswould fail if the content-type parameters were not properly formatted. But, after this PR, it will just ignore them.i.e. previously, this would return
false:typeis.is('application/json; charset:utf-8', 'json') // Notice the ":" instead of "=" in charsetBut after this PR, it will return
"json".This behaviour was documented (...If the
Content-Typeheader is invalid...):https://github.com/jshttp/type-is/blob/7d19b7aab1ad671f59ba157ae0640cd4b1302ca5/README.md?plain=1#L35-L38
But it was not tested in the case of invalid parameters. I am not sure of the best way forward:
- Keep validating parameters, and make test cases for it,
- Or update the documentation to clarify that parameters will not be validated.
-
After this PR,
media-typerdependency could be upgraded to 1.1.0.