Skip to content

Fix JSON parsing of escaped strings #7545

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

Merged
merged 7 commits into from
Apr 24, 2025

Conversation

kripken
Copy link
Member

@kripken kripken commented Apr 23, 2025

To find the end of a string, we must be more careful of escaping - we assumed
any \" was an escaped double-quote, but it might be part of \\", that is, where
there is an escaped \ before us, and the double-quote is not escaped itself.

This fixes StringLifting on real-world Java code I am testing on.

@kripken kripken requested a review from tlively April 23, 2025 23:28
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

if (*close == '\\') {
// Skip the \ and the character after it, which it escapes.
close++;
assert(*close);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how useful this assertion is.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is necessary, because if this is 0, then it is not valid to do the next close++ and then read *close, which would be past the string.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, it's checking for the end of a C-style string. Can we add a && "unexpected end of string" to clarify?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see this file was switched to throwing from asserts meanwhile, as I merged in main. I updated the errors to have text like that.

close++;
assert(*close);
}
close++;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: ++close here and above.

Copy link
Member Author

Choose a reason for hiding this comment

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

These are just pointers, and the current code is consistent with usage elsewhere in the file - is it worth adding an inconsistency here do you think?

Copy link
Member

Choose a reason for hiding this comment

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

No, probably not.

@kripken kripken merged commit bba8a10 into WebAssembly:main Apr 24, 2025
14 checks passed
@kripken kripken deleted the json.escape.slash branch April 24, 2025 18:03
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

Successfully merging this pull request may close these issues.

2 participants