Skip to content
New issue

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

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

Already on GitHub? # to your account

Stop swallowing JSON parse errors #67

Merged
merged 3 commits into from
May 17, 2024

Conversation

cooperka
Copy link
Contributor

@cooperka cooperka commented Apr 30, 2024

If unparseable JSON is provided, the library should fail loudly rather than ignoring the input.

Looking through the blame, I couldn't find any specific reason why safe_json_parse is meant to be safe -- in fact, because it swallows up errors and pretends that there's no problem, it made things very confusing to diagnose.

Let me know if you'd like me to take this in any particular direction and I'm happy to update the PR.

@cooperka cooperka changed the title make safe_json_parse unsafe Stop swallowing JSON parse errors Apr 30, 2024
@cooperka
Copy link
Contributor Author

Edited to add context, fyi (GitHub posted this PR from their editor without a description)

@@ -65,7 +65,7 @@ def verify_array_index!(path, index, size)
def safe_json_parse(data)
JSON.parse(data)
rescue JSON::ParserError
nil
raise JSON::ParserError, "Malformed JSON in multipart form data"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is no longer safe, so let's remove it and use JSON.parse directly where needed.

@fuelen
Copy link
Collaborator

fuelen commented May 1, 2024

I don't remember why it was done like this, so yes, let's try to remove safety :)

@cooperka
Copy link
Contributor Author

thanks for your patience -- feedback addressed and ready for re-review.

@fuelen
Copy link
Collaborator

fuelen commented May 16, 2024

Thank you.
Could you adjust tests as well?

@@ -6,3 +6,4 @@
/pkg/
/spec/reports/
/tmp/
/vendor/bundle/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common path for local gems to be stored

example.run
described_class.strict_mode = mode
end

Copy link
Contributor Author

@cooperka cooperka May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not sure what changed here, tabs and line endings seem unaltered 🤷

View the diff with ?w=1 in URL params to show actual changes.

@cooperka
Copy link
Contributor Author

Done! I basically just changed foo to {} so the JSON wouldn't fail.

@fuelen
Copy link
Collaborator

fuelen commented May 17, 2024

Looks good. Thank you for the contribution!

@fuelen fuelen merged commit f50fe1e into jetruby:master May 17, 2024
3 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants