Skip to content

fix(common): reject non-numeric items in ParseArrayPipe with items Number - #17876

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
SulimanAbdulrazzaq:fix/parse-array-number-items
Sep 25, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
SulimanAbdulrazzaq:fix/parse-array-number-items

Conversation

@SulimanAbdulrazzaq

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

With new ParseArrayPipe({ items: Number }), each item goes through JSON.parse and is then checked with +value / isNaN. Anything that coerces to a number passes:

input result on master
?ids=1,true [1, 1]
?ids=1,false [1, 0]
?ids=1,[2] [1, 2]
?ids=1, ,2 [1, 0, 2]
?ids=1,0x10 [1, 16]
?ids=1,Infinity [1, Infinity]
body [1, true] [1, 1]

ParseIntPipe and ParseFloatPipe reject all of these.

Issue Number: N/A

What is the new behavior?

Number items must be a finite number, or a non-blank string that Number() turns into a finite number without a 0x/0b/0o prefix (the same prefixes ParseFloatPipe rejects). Anything else fails with the existing [i] item must be a number message. Numeric strings that passed before still pass (1, 2, -3.5, 1e3, 01, +4, .5).

Two tests were added to parse-array.pipe.spec.ts. On master, the first fails with promise resolved "[ 1, 1 ]" instead of rejecting. With this change, the 212 tests in packages/common/test/pipes pass, and oxlint and prettier report no problems on the changed files.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Arrays that pass validation are unchanged. The only inputs this now rejects are values that were being silently turned into numbers.

…mber

ParseArrayPipe validated Number items with `+value` after JSON.parse, so
anything that coerces to a number passed: `true` became 1, `false` 0,
`[2]` 2, a blank item 0, `0x10` 16 and `Infinity` Infinity. Only accept
finite numbers and numeric strings, and reject radix prefixes the same
way ParseIntPipe and ParseFloatPipe do.
@kamilmysliwiec
kamilmysliwiec merged commit 1fbe1c5 into nestjs:master Sep 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants