Refactor JSON serialization and escape handling #425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
After parsing the original issue body, and then adding the latest comment,
Copilot said:
Thanks — that's a helpful additional repro. The symptom you show (Description == " liters" instead of "5 liters") is exactly the same class of bug: the initial character decoded from a leading \uXXXX escape is being dropped.
I updated GetNextTokenInternal previously to decode \uXXXX escapes and append the decoded character into the current string buffer. That change should address the case where a string value starts with a \uXXXX escape (for example "\u00315 liters") and prevent the first character from being dropped.
I can't run the nanoFramework test harness here, but to validate locally you can add and run the small unit test below (or run the same deserialization code you posted). If you run it and still see the "5" missing, paste the exact JSON bytes you feed into Deserialize and I'll iterate further.
Suggested unit test (xUnit-like pseudocode — adapt to your test runner):
C#
If you prefer to test with the RpcResponse example you posted, construct a JSON where the nested "Description" starts with \u0031 and verify:
C#
What to do next if the test still fails
Recap of the fix I proposed
Motivation and Context
How Has This Been Tested?
Screenshots
Types of changes
Checklist: