fix(airdrops): strict amount parsing in parseCSV - #137
Open
devkryssie wants to merge 1 commit into
Open
Conversation
…#134 Replace parseFloat with strictParseAmount() helper that validates amount strings against /^-?\d+(\.\d+)?$/ before accepting them. Previously: - parseFloat('1,000') → 1 (silent truncation) - parseFloat('100USD') → 100 (silent truncation) - missing/empty amount → row silently dropped, no error Now all three cases throw an AppError(VALIDATION_ERROR) with the 1-indexed row number and the raw value that failed, matching the row-numbered error style used elsewhere in the same handler. Tests added for all three malformed-amount scenarios.
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.
Summary
Fixes #134.
parseCSV()usedparseFloatto parse recipient amounts, which silently truncates malformed strings and causes bad amounts to be silently accepted or bad rows to be silently dropped:"1,000"(comma-formatted)1— silently mangled"100USD"(trailing garbage)100— silently mangled""/ missingChanges
src/routes/airdrops.jsstrictParseAmount(raw)helper that validates against/^-?\d+(\.\d+)?$/before accepting a value.parseCSV()now throwsAppError('VALIDATION_ERROR',recipient ${rowCount}: amount is missing or invalid..., 400)for any invalid amount, matching the row-numbered error style already used for invalid/duplicate addresses in the same handler.if (address && !Number.isNaN(amount)) { results.push(...) }fallthrough.test/airdrops.test.jsWhat was tested
node_modulesnot available in the dev environment due to no network access).main(fast-forward, no divergence).