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

THRIFT-5474: TSimpleJsonProtocol with inner quotes does not produce valid JSON. #2474

Conversation

thealmightygrant
Copy link

There is an issue in the generation of JSON from the TSimpleJSONProtocol, where if there are quotes inside of a string, then those quotes will not be serialized correctly. These quotes need one more layer of escaping to produce valid JSON.

I have also added the Jackson library to these tests to ensure that any future changes to this library produce valid JSON.

  • Did you create an Apache Jira ticket? (not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

…alid JSON.

There is an issue in the generation of JSON from the TSimpleJSONProtocol, where if there are quotes inside of a string, then those quotes will not be serialized correctly. These quotes one more layer of escaping to produce valid JSON. I have included JSON parsing into the test for TSimpleJSONProtocol to ensure that this does not happen if there are changes to this class in the future.
@@ -314,6 +314,7 @@ public void writeString(String str) throws TException {
char c = str.charAt(i);
switch (c) {
case '"':
escape.append('\\');
case '\\':
Copy link
Member

Choose a reason for hiding this comment

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

So this is the whole net patch content, buried under a pile of unrelated other changes.
Plus I don't think this change is even remotely correct

Copy link
Author

Choose a reason for hiding this comment

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

I'll work up a more complete test example for you today. I can see how you might not think this would make a difference. The other code is intended to try to parse the JSON strings produced from these tests, it will throw an exception otherwise.

@thealmightygrant
Copy link
Author

I was unable to reproduce this in the latest version of thrift, so it must be some artifact of the version that I am using that is no longer relevant. For posterity, this occurs in thrift 0.9.3. See the latest commit for an explicit example of how this would fail in that version of the thrift library.

@emmenlau
Copy link
Member

Thanks for the effort, @thealmightygrant ! Its always nice to see people going to the effort of making a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants