cdent / gabbi

Declarative HTTP Testing for Python and anything else
http://gabbi.readthedocs.org/
Other
148 stars 34 forks source link

Constrain how the JSONHandler accepts content-types #302

Closed cdent closed 2 years ago

cdent commented 2 years ago

Some formats that look like they might be JSON, based on the media-type in the content-type header are not actually valid JSON. This presents problems with tests trying to decode, but being unable to do so, causing unexpected failures.

These changes update the accepts method in the JSONHandler to be more specific and adds tests to cover it.

As part of this some test which showed that we accept "application/json-home" as valid JSON have been removed. That media type is not considered legitimate. See: https://github.com/mnot/I-D/issues/172

Note that this change is an improvement, but it is not 100% reliable as there is no good way to be so because the world is complex and ambiguous, which is part of why #301 was done: to deal with gaps.

Thanks to @FND for ideas from #298.

Fixes #296