Skip to content

test: add coverage for preservePath - #1454

Merged
UlisesGascon merged 1 commit into
expressjs:mainfrom
kory-kaai:test/preserve-path-coverage
Aug 24, 2026
Merged

UlisesGascon merged 1 commit into
expressjs:mainfrom
kory-kaai:test/preserve-path-coverage

Conversation

@kory-kaai

Copy link
Copy Markdown
Contributor

Closes #1453.

preservePath had no test coverage — grep -r preservePath test/ returned nothing — even though it changes what consumers see in file.originalname. This adds the two cases described in the issue:

  • default (preservePath unset): a file sent as filename="a/b/c.txt" arrives with originalname === 'c.txt'
  • preservePath: true: the same upload keeps originalname === 'a/b/c.txt'

Both go through util.submitForm like the existing tests. The full client path is set with form-data's filepath option, since filename is passed through path.basename internally and so can't express the path segments this option exists to preserve.

Verified the assertions actually exercise the option: forcing preservePath: false in lib/make-middleware.js fails the second case with -c.txt / +a/b/c.txt, and it passes again once reverted.

npm test goes from 84 to 86 passing, and npm run lint is clean. No source or existing test files are touched.

@UlisesGascon UlisesGascon self-assigned this Aug 24, 2026

@UlisesGascon UlisesGascon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fast @kory-kaai! Great work!

@UlisesGascon
UlisesGascon merged commit e4e3826 into expressjs:main Aug 24, 2026
22 checks passed
@UlisesGascon UlisesGascon mentioned this pull request Aug 25, 2026
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.

test: add coverage for preservePath

2 participants