Skip to content

price: reject negative inputs in Parse - #6031

Merged
urvisavla merged 1 commit into
mainfrom
price-parse-reject-negatives
Oct 23, 2026
Merged

urvisavla merged 1 commit into
mainfrom
price-parse-reject-negatives

Conversation

@urvisavla

@urvisavla urvisavla commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

price.Parse now returns ErrNoNegatives for any input that starts with -. The grammar regexp no longer accepts a leading minus.

Input Before After
-1 {-1, 1}, no error (rejected later by Validate()) ErrNoNegatives
-2147483649 {2147483647, 1}, passes Validate() ErrNoNegatives
-2147483647.9 {1, 10}, passes Validate() ErrNoNegatives

Why

Parse accepted a leading minus but never checked the sign of the result:

🤖 Generated with Claude Code

Parse accepted a leading minus but never checked the sign. Values below
MinInt32 wrapped to a valid-looking positive price. Return ErrNoNegatives
for any input starting with "-".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Copilot AI left a comment

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.

🟢 Approval recommended

The reviewed changes address the negative-input issue and include appropriate regression and validation coverage.

No open issues 🎉

What changed in this PR

This pull request updates price.Parse to reject negative inputs before conversion can produce invalid or wrapped xdr.Price values.

Changes:

  • Removes leading-minus support from the price grammar.
  • Returns ErrNoNegatives for inputs beginning with -.
  • Adds regression tests for negative values, wraparound cases, and successful parse validation.
File Summary
price/​main.go Rejects negative price inputs and updates the accepted grammar.
price/​main_test.go Tests negative-input rejection, wraparound cases, and output validation.

Review effort: Lite

@urvisavla
urvisavla marked this pull request as ready for review October 23, 2026 00:22
@urvisavla
urvisavla merged commit 6eea72f into main Oct 23, 2026
12 checks passed
@urvisavla
urvisavla deleted the price-parse-reject-negatives branch October 23, 2026 05:37
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.

3 participants