Escape JSON special characters in Serialize.tryToJSONString#214
Open
janezpodhostnik wants to merge 1 commit into
Open
Escape JSON special characters in Serialize.tryToJSONString#214janezpodhostnik wants to merge 1 commit into
janezpodhostnik wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes: #213
Description
Adds an
escapeJSONStringhelper toSerialize.cdcthat escapes\,", and control characters (U+0000–U+001F) per RFC 8259 §7, and applies it in theString,String?, andCharactercases oftryToJSONString. Dictionary keys indictToJSONStringare serialized through the same String case, so they are covered as well.Escaping is a single pass over UTF-8 bytes with a fast path that returns the input unchanged when nothing needs escaping; multi-byte UTF-8 sequences pass through untouched.
Includes unit tests for all escape classes (quotes, backslash,
\n/\r/\t,\b/\f,\u00XXcontrol chars, multi-byte passthrough, dict keys) and a regression test serializing an NFT with quotes, a newline, and a tab in its name/description to a parseable JSON data URI.For contributor use:
mainbranchFiles changedin the Github PR explorer