Skip to content

fix(solana-pay): accept amount=0 in parseSolanaPayURL - #354

Open
latent-9 wants to merge 1 commit into
gillsdk:masterfrom
latent-9:fix/solana-pay-zero-amount
Open

fix(solana-pay): accept amount=0 in parseSolanaPayURL#354
latent-9 wants to merge 1 commit into
gillsdk:masterfrom
latent-9:fix/solana-pay-zero-amount

Conversation

@latent-9

Copy link
Copy Markdown

Problem

parseSolanaPayURL rejects a transfer request with amount=0, even though 0 is a valid amount. In parseTransferRequestURL (packages/solana-pay/src/parse-url.ts), the amount block accepts "0" via the regex and then throws on it:

if (!/^\d+(\.\d+)?$/.test(amountParam)) throw new SolanaPayParseURLError("amount invalid"); // accepts "0"
amount = parseFloat(amountParam);                                                            // 0
if (!amount) throw new SolanaPayParseURLError("amount invalid");                             // !0 is true -> throws
if (Number.isNaN(amount)) throw new SolanaPayParseURLError("amount NaN");
if (amount < 0) throw new SolanaPayParseURLError("amount negative");
// 0 is a valid `amount`

parseFloat("0") is 0, so !amount is true and the parse throws "amount invalid". This contradicts both the regex on the line above (which accepts "0") and the comment on the line below (// 0 is a valid amount). The same happens for amount=0.0.

  • Input: solana:nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5?amount=0
  • Current: throws SolanaPayParseURLError: amount invalid
  • Expected: returns { recipient, amount: 0, ... }

Summary of Changes

Drop the if (!amount) guard. The regex already rejects empty and non-numeric input, and the NaN and negative checks remain, so 0 now parses while every previously-invalid input still throws. Adds a regression test (should parse a zero amount); the existing invalid-amount cases (1milliondollars, -0.1, -100) stay covered by the regex.

Fixes the rejection of amount=0 / amount=0.0.

parseTransferRequestURL rejected amount=0: parseFloat("0") is 0 and the guard
`if (!amount) throw` treats 0 as invalid, even though the regex on the line
above accepts "0" and the comment right below states "0 is a valid amount".
Drop the guard; the regex already rejects empty and non-numeric input, and the
NaN and negative checks remain. Adds a regression test.
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 43c6a4c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant