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

[ruby] decode_json unexpected / inconsistent behaviour parsing JSON #8135

Closed
mt-kelvintaywl opened this issue Dec 11, 2020 · 3 comments
Closed

Comments

@mt-kelvintaywl
Copy link

mt-kelvintaywl commented Dec 11, 2020

What version of protobuf and what language are you using?
Protobuf version: 3
ruby gem version: 3.12.0.rc.1
Language: Ruby

What operating system (Linux, Windows, ...) and version?
MacOS 10.14.4

What runtime / compiler are you using (e.g., python version or gcc version)
Ruby 2.7

What did you do?

Assuming i have a generated Ruby class from Protobuf, called MyMessage

# raises Google::Protobuf::ParseError (expected)
MyMessage.decode_json("I cannot understand this", ignore_unknown_fields: true)

# returns a MyMessage.new object (expected since number is a valid JSON)
MyMessage.decode_json("1", ignore_unknown_fields: true)

# returns a MyMessage.new object (unexpected? this is a string so I expected it to throw)
MyMessage.decode_json("1 cannot understand this", ignore_unknown_fields: true) 

Would this be a known or expected behaviour? 🙇

@haberman
Copy link
Member

The Ruby JSON decoder may not be properly verifying that it is at end-of-file.

There is a major change to the Ruby implementation coming soon. I'll revisit this bug after that is complete, and we can see if the new JSON parser has the same issue.

@mt-kelvintaywl
Copy link
Author

HI @haberman thank you for the updates and details :)
Looking forward to the new releases 🙇

would there also be a public roadmap that we can track the progress of this? 🤔

@haberman
Copy link
Member

I just tested your examples on #8184 and all of your examples throw errors now. This is expected since parsing a message from JSON requires a top-level object in {}.

Your second example now throws this error: Error occurred during parsing: Error parsing JSON @1:0: Expected: '{'

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