fix(solana-pay): accept amount=0 in parseSolanaPayURL - #354
Open
latent-9 wants to merge 1 commit into
Open
Conversation
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.
|
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.
Problem
parseSolanaPayURLrejects a transfer request withamount=0, even though0is a valid amount. InparseTransferRequestURL(packages/solana-pay/src/parse-url.ts), the amount block accepts"0"via the regex and then throws on it:parseFloat("0")is0, so!amountistrueand 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 foramount=0.0.solana:nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5?amount=0SolanaPayParseURLError: amount invalid{ recipient, amount: 0, ... }Summary of Changes
Drop the
if (!amount)guard. The regex already rejects empty and non-numeric input, and theNaNand negative checks remain, so0now 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.