Skip to content

reject a lone sign token as a number in decodeNumber#1703

Open
SABITHSAHEB wants to merge 1 commit into
open-source-parsers:masterfrom
SABITHSAHEB:reject-lone-sign-number
Open

reject a lone sign token as a number in decodeNumber#1703
SABITHSAHEB wants to merge 1 commit into
open-source-parsers:masterfrom
SABITHSAHEB:reject-lone-sign-number

Conversation

@SABITHSAHEB

Copy link
Copy Markdown
Contributor

a number token that is only a sign ("-", including as an array or object element) never enters decodeNumber's digit loop, so it fell through as integer 0 instead of being rejected; route a sign-only token to decodeDouble, which rejects it, in both Reader and OurReader.

// below never runs and would otherwise decode it as zero. Reject it via
// decodeDouble, matching how a non-digit inside the token is handled.
if (current == token.end_)
return decodeDouble(token, decoded);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just return false here instead of invoking decodeDouble?

// below never runs and would otherwise decode it as zero. Reject it via
// decodeDouble, matching how a non-digit inside the token is handled.
if (current == token.end_)
return decodeDouble(token, decoded);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here -- if current == token.end_ and isNegative, can you just return false?

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