Conversation
get_unicode_codepoint returned Ok((0, _)) for a high surrogate that is not followed by a `\u` escape, and for a surrogate pair with invalid hex digits. The 0 is a leftover sentinel: when this code returned the number of bytes written, 0 meant failure and callers checked `o == 0`. Since 29d9998 it returns the code point instead, so the 0 became U+0000 and "\ud800" parsed as "\0" without an error. Return InvalidUnicodeCodepoint in both places, and add a regression test covering the lone-surrogate forms (fails before this change). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Fixes #481.
get_unicode_codepointreturnedOk((0, src_offset))for a high surrogate not followed by a\uescape, and for a surrogate pair with invalid hex digits in either half. The0was the old "bytes written = 0 means failure" sentinel fromhandle_unicode_codepoint. Since 29d9998 the function returns a code point, so it now means U+0000 and"\ud800"parsed as"\0".This change returns
Err(ErrorType::InvalidUnicodeCodepoint)in both places. Everyparse_strimplementation already maps an error from here toInvalidUnicodeCodepointat the escape's position, so no caller changes are needed.Test:
lone_high_surrogate_is_an_errorcovers"\ud800","\ud800x",["\udbff"], a surrogate inside a string,"\ud800\n","\ud800\uzzzz","\ud800A"and"\udc00"through bothto_tapeandto_borrowed_value, and checks that a valid pair still decodes. It fails without the fix (accepted: "\ud800") and passes with it.cargo testpasses on aarch64 (macOS, NEON) and x86_64 (Linux, AVX2), andcargo fmt --checkis clean.Side note, not changed here: the
if o == 0checks afterhandle_unicode_codepointin the avx2/sse42/neon/simd128/portableparse_strcan no longer trigger, becausecodepoint_to_utf8writes at least one byte. I left them in to keep this diff minimal. Happy to remove them in a follow-up if you prefer.🤖 Generated with Claude Code