Repository navigation
Reject a NUL inside the exponent in Parse [patch] - #206
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
long.Parse ignores trailing NULs by itself, so a NUL that the parse kept because white space, a sign or a currency symbol followed it reached the exponent as "1\0" and was accepted: "3e1\0 " parsed as 30 and "3e1\0-" as -30, where decimal and double throw. An exponent containing a NUL is now a FormatException; NULs at the very end are still ignored. Fixes #203 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW4B4xxTAPzAHBD4zKk
|
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 #203
What changed
TrimTrailingNulsrightly keeps a NUL that is followed by white space, a sign or a currency symbol. Once those are trimmed, though, the exponent text is"1\0", andlong.Parseignores trailing NULs by itself, so"3e1\0 "parsed as 30 and"3e1\0-"as -30.decimalanddoubleboth throw for these.FromParsedPartsnow throwsFormatExceptionfor an exponent text containing a NUL before handing it tolong.Parse. NULs at the very end ("3e1\0","3e1\0\0") are trimmed earlier and still parse as 30.Tests
ParseRejectsANulInsideTheExponentcovers the issue's five inputs. Each asserts thatdecimalanddoublereject it, that bothTryParseoverloads return false, and thatParsethrowsFormatException. All five fail without the fix.ParseIgnoresTrailingNulsAsDecimalDoesgains"3e1\0"and"3e1\0\0".$case uses an invariantNumberFormatInfowithCurrencySymbol = "$"rather thanen-US, followingPreciseNumberParseAffixTests, so it also runs in globalization-invariant mode.Generated by Claude Code