Use quirks_mode when parsing JSON
souliane opened this issue · 1 comments
Please set the option ":quirks_mode => true" when calling JSON.parse in
pact/consumer/mock_service/rack_request_helper.rb, line 31.
Ruby JSON library doesn't consider serialized string as a correct JSON value (which is is false statement!) and this quirks_mode is needed for working with string encoded as JSON:
https://makandracards.com/makandra/15611-how-to-fix-unexpected-token-error-for-json-parse
Hi @souliane. Unfortunately, the change would not be as simple as that - there are implications for interoperability with the jvm and Rust implementations.
@uglyog I've done a bit more reading on this, and I think I've been convinced that a top level value is now accepted as a JSON "document" in the modern RFCs. Here's a relevant stackoverflow post https://stackoverflow.com/questions/3833299/can-an-array-be-top-level-json-text
Someone on that thread claims that:
There is some confusion, seen in the other comments. The "application/json" media type allows only object or array at the top-level for JSON-text, per JSON RFC.
but I can't find any reference to that in the spec http://www.ietf.org/rfc/rfc4627.txt?number=4627
How would the jvm and Rust implementations handle this?
@souliane putting aside the implementation details, using a string as a top level element is generally considered to be bad practice, as it doesn't allow for any extensibility in the future, is poorly supported (as evidenced by the issue you have raised) and according to the stackoverflow post mentioned above, has security implications. Is there a particular reason why you can't use an object?