-
-
Notifications
You must be signed in to change notification settings - Fork 722
refactor(parser): improve safety of char to bytes conversions #13193
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
refactor(parser): improve safety of char to bytes conversions #13193
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #13193 will not alter performanceComparing Summary
Footnotes |
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.
Pull Request Overview
This PR enhances the safety of character-to-bytes conversions by adding compile-time assertions. The changes ensure that the to_bytes function correctly handles UTF-8 encoding and validates expected byte values for replacement characters.
- Adds assertions to verify that characters have the expected UTF-8 byte length in
to_bytesfunction - Replaces a comment with a const assertion to validate the first byte of the lossy replacement character
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/lexer/template.rs | Added assertion to verify character byte length in to_bytes function |
| crates/oxc_parser/src/lexer/string.rs | Added assertion to to_bytes function and replaced comment with const assertion for replacement character byte value |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
I don't think much to argue on this one (despite Copilot's best attempts). So merging without further review. |
Merge activity
|
8cbac03 to
6c5f7e5
Compare
|
Why aren't you merging this, Graphite? |

to_bytesconverts acharto a series ofNbytes. Add an assertion to make sure that the character is actuallyNbytes long.Also, const assert the value of
LOSSY_REPLACEMENT_CHAR_FIRST_BYTE, rather than just a comment stating what we expect it to be.