fix: do not consume maxCount for files skipped by fileFilter#1426
Open
Sagargupta16 wants to merge 1 commit into
Open
fix: do not consume maxCount for files skipped by fileFilter#1426Sagargupta16 wants to merge 1 commit into
Sagargupta16 wants to merge 1 commit into
Conversation
wrappedFileFilter decremented the field's remaining-count before the user
fileFilter ran, so a file skipped via cb(null, false) still consumed a
slot. With e.g. .array('docs', 1), a skipped file made the next accepted
file on the same field fail with LIMIT_UNEXPECTED_FILE, even though zero
files had been stored. Decrement only after the filter accepts the file.
Closes expressjs#1419
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.
Description
wrappedFileFilterdecrements the field's remaining-count before the user'sfileFilterruns:So a file the user skips with
cb(null, false)still consumes a slot. With.array('docs', 1), uploading a skipped file followed by an accepted file on the same field makes the second file fail withLIMIT_UNEXPECTED_FILE— even though zero files were stored. Per the README,cb(null, false)means the file is silently skipped (never added toreq.files), so it must not count againstmaxCount. Fixes #1419.Fix
Move the decrement inside the
fileFiltercallback and only decrement when the file is actually accepted:This routes all callers (
.single/.array/.fields) through one guard. Truly unexpected fields and accepted files beyondmaxCountstill error as before.Test
Added a regression test in
test/file-filter.js: a.array('docs', 1)upload where the filter skips the first same-field file and accepts the second — asserts exactly one file (tiny1.dat) is stored with no error. The test fails onmainwithout the fix (LIMIT_UNEXPECTED_FILE) and passes with it; existing fileFilter tests remain green.