-
Notifications
You must be signed in to change notification settings - Fork 12k
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
ref: added functionality to escapeJSONstrings (ref: #5251) #5508
base: master
Are you sure you want to change the base?
Conversation
|
Is my approach correct , am i working right on this pr @Amxx ? |
|
||
function _escapeJsonString(string memory input) private pure returns (string memory) { | ||
bytes memory buffer = bytes(input); | ||
bytes memory output = new bytes(buffer.length * 2); // Allocate max possible space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this allocated a lot of memory that is not freed. This is quite expensive. Alternatives are:
- count number of "extra chars" in a loop, and allocate the right size directly
- resize the output buffer without a copy, and move the free memory ptr, using assembly
Co-authored-by: Hadrien Croubois <[email protected]>
Fixes #5251
A function to escape special characters in JSON strings
Handles key characters like quotes ("), backslashes (), forward slashes (/), and control characters (\n, \t, \r, etc.)
Prevents JSON injection attacks in NFT metadata and other use cases
PR Checklist
npx changeset add
)