Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use quirks_mode when parsing JSON #92

Open
souliane opened this issue Jul 4, 2018 · 1 comment
Open

Use quirks_mode when parsing JSON #92

souliane opened this issue Jul 4, 2018 · 1 comment

Comments

@souliane
Copy link

souliane commented Jul 4, 2018

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

@bethesque
Copy link
Member

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?

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

No branches or pull requests

2 participants