type-is icon indicating copy to clipboard operation
type-is copied to clipboard

Adds support for `HTAB` as well as `SP` as whitespace separators in `content-type` headers

Open rg2011 opened this issue 1 year ago • 0 comments

Fixes issue #52. Notes:

  • The fix applies to both typeis and typeis.is, instead of just typeis.

    This is because typeis.is can receive a req-like or res-like object (this behaviour is undocumented but tested). I wanted to avoid situations where typeis(req, ...) would work but typeis.is(req, ...) would not.

  • The fix breaks backward compatibility in that, previously, typeis would 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 charset

    But after this PR, it will return "json".

    This behaviour was documented (...If the Content-Type header 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-typer dependency could be upgraded to 1.1.0.

rg2011 avatar Jan 28 '24 23:01 rg2011