-
-
Notifications
You must be signed in to change notification settings - Fork 6
Remove unreachable fallback branch in UTF-16 decode step #1540
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
Changes from all commits
fefab25
b7ae07e
fe050dd
b98491f
4e2b673
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,8 @@ const codePointToUtf16 = codePoint => { | |
| export const fromCodePointList | ||
| = flatMap(codePointToUtf16) | ||
|
|
||
| const isInU16Range = contains(0x0000, 0xFFFF) | ||
|
|
||
| /** | ||
| * Validates whether a given 16-bit unsigned integer (U16) falls within the valid range for UTF-16 code units. | ||
| * | ||
|
|
@@ -135,9 +137,14 @@ export const fromCodePointList | |
| * const edgeCaseHigh = u16(0xFFFF) // true: Maximum valid value for UTF-16 | ||
| * ``` | ||
| * | ||
| * `U16` is just `number`, so this also rejects non-integers — `isBmpCodePoint`, | ||
| * `isHighSurrogate`, and `isLowSurrogate` only partition the *integers* in | ||
| * `0x0000`–`0xFFFF` with no gap; a fractional value would fall between two of | ||
| * those ranges and be misclassified downstream if it were let through here. | ||
| * | ||
| * @type {(i: U16) => boolean} | ||
| */ | ||
| const u16 = contains(0x0000, 0xFFFF) | ||
| const u16 = i => Number.isInteger(i) && isInU16Range(i) | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -191,9 +198,11 @@ const utf16ByteToCodePointOp = (word, state) => { | |
| const low = word - 0xdc00 | ||
| return [[(high << 10) + low + 0x10000], null] | ||
| } | ||
| // `isLowSurrogate`, `isBmpCodePoint`, and `isHighSurrogate` partition the | ||
| // full `u16` range with no gap, and `isLowSurrogate` was already ruled out | ||
| // above, so a non-BMP `word` here is always a high surrogate. | ||
| if (isBmpCodePoint(word)) { return [[state | errorMask, word], null] } | ||
| if (isHighSurrogate(word)) { return [[state | errorMask], word] } | ||
| return [[state | errorMask, word | errorMask], null] | ||
| return [[state | errorMask], word] | ||
|
Comment on lines
+201
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This change implements AGENTS.md reference: AGENTS.md:L1170-L1176 Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+201
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This commit changes authored FunctionalScript code but leaves AGENTS.md reference: AGENTS.md:L1194-L1203 Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already added in b7ae07e, before this review ran — see Generated by Claude Code |
||
| } | ||
|
|
||
|
|
||
|
|
||
This file was deleted.
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.
U16is only an alias fornumber, andu16checks only the inclusive numeric range, so values between the surrogate ranges are reachable. For example, decoding[0xd800, 0xdbff + 0.5, 0xdc00]now treats the fractional middle value as a pending high surrogate and emits0x10fc00as if it were a valid pair; the removed fallback previously emitted masked errors for both invalid units. Retain a fallback or reject non-integers before unconditionally treating this branch as a high surrogate.AGENTS.md reference: AGENTS.md:L401-L403
Useful? React with 👍 / 👎.
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.
Confirmed and fixed in fe050dd — I verified the gap is real (
containsis a plain<=/>=check, so e.g.56319.5matched none ofisHighSurrogate/isLowSurrogate/isBmpCodePoint). Tightenedu16withNumber.isIntegerso the three predicates' exhaustive-partition guarantee actually holds for every input the function can receive, and added proof cases for a fresh and a pending-state fractional word.Generated by Claude Code