Escape control characters in Strings.escapeJSON#6344
Escape control characters in Strings.escapeJSON#6344ernestognw merged 8 commits intoOpenZeppelin:masterfrom
Conversation
|
The latest updates on your security scan. Learn more about OpenZeppelin Platform.
|
|
WalkthroughThe changes update the Strings.escapeJSON function to extend control character escaping to cover the full range U+0000 to U+001F per RFC-4627. Previously, only seven specific control characters were escaped. The implementation removes a bitmask-based lookup constant and replaces it with explicit control character detection that outputs Unicode escape sequences (\u00XX) for control characters. The test suite is expanded to verify escaping behavior for all ASCII control characters in the range U+0000 to U+001F. A breaking change entry is added to the changelog documenting the extended escaping behavior. 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
|
||
| bytes16 private constant HEX_DIGITS = "0123456789abcdef"; | ||
| uint8 private constant ADDRESS_LENGTH = 20; | ||
| uint256 private constant SPECIAL_CHARS_LOOKUP = |
There was a problem hiding this comment.
Why not keep that lookup table, and extend it to cover all control chars?
uint256 private constant SPECIAL_CHARS_LOOKUP =
(0xffffffff) | // first 32 bytes corresponding to the control characters
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
contracts/utils/Strings.sol
Outdated
| (1 << 0x0a) | // newline | ||
| (1 << 0x0c) | // form feed | ||
| (1 << 0x0d) | // carriage return | ||
| 0xffffffff | // first 32 bytes corresponding to the control characters |
There was a problem hiding this comment.
| 0xffffffff | // first 32 bytes corresponding to the control characters | |
| 0xffffffff | // first 4 bytes corresponding to the control characters |
or
| 0xffffffff | // first 32 bytes corresponding to the control characters | |
| 0xffffffff | // first 32 bits corresponding to the control characters |
ernestognw
left a comment
There was a problem hiding this comment.
LGTM, can't approve my own PR
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Fixes #????
PR Checklist
npx changeset add)