Skip to content

Conversation

@rg2011
Copy link

@rg2011 rg2011 commented Jan 28, 2024

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...):

    type-is/README.md

    Lines 35 to 38 in 7d19b7a

    Checks if the `request` is one of the `types`. If the request has no body,
    even if there is a `Content-Type` header, then `null` is returned. If the
    `Content-Type` header is invalid or does not matches any of the `types`, then
    `false` is returned. Otherwise, a string of the type that matched is returned.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant