Skip to content

compare special-value symbols against the whole input character - #300

Merged
floitsch merged 1 commit into
google:masterfrom
Ramya-9353:uc16-symbol-narrowing
Aug 3, 2026
Merged

compare special-value symbols against the whole input character#300
floitsch merged 1 commit into
google:masterfrom
Ramya-9353:uc16-symbol-narrowing

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: with infinity_symbol_ = "Infinity" and nan_symbol_ = "NaN", the uc16 overload accepts non-ASCII text as a special value. U+014E 'a' 'N' and U+FF4E 'a' 'N' both return NaN, U+FF49 'n' 'f' 'i' 'n' 'i' 't' 'y' returns Infinity, and 'N' U+0161 'N' returns NaN, where each should have given junk_string_value with processed_characters_count == 0. Under ALLOW_CASE_INSENSITIVITY with the symbol "nan", U+014E 'a' 'n' matches too.

Cause: the symbols are matched through helpers declared on char (ConsumeFirstCharacter for the leading character, ToLower/Pass inside ConsumeSubStringImpl for the rest), so a 16-bit input character is truncated to its low byte before the comparison and any code point ending in the expected symbol byte aliases it. This is the conversion the C4244 suppression at the top of the file is about.

Fix: compare the unsigned code-unit value of the input character and of the symbol byte. The char overloads are unaffected because both sides pass through unsigned char, and ASCII matching, case-insensitive included, is unchanged.

@google-cla

google-cla Bot commented Aug 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@floitsch

floitsch commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks.

@floitsch
floitsch merged commit 9ae489f into google:master Aug 3, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants