Skip to content

fix: fall back to path.extname when multi-dot extension has invalid chars#1070

Open
ordinary9843 wants to merge 1 commit intonode-formidable:masterfrom
ordinary9843:fix/keepextensions-invalid-chars
Open

fix: fall back to path.extname when multi-dot extension has invalid chars#1070
ordinary9843 wants to merge 1 commit intonode-formidable:masterfrom
ordinary9843:fix/keepextensions-invalid-chars

Conversation

@ordinary9843
Copy link

When keepExtensions: true is set, filenames containing special characters like parentheses cause the wrong extension to be stored.

'test(.123).pdf'  →  stored as  .123   (wrong)
'EERS 1.1-CUR.pdf'  →  stored as  .1   (wrong)

The root cause is in _getExtension: when a filename has multiple dots, it slices from the first dot and truncates at the first invalid character. For test(.123).pdf, the first dot falls inside the parentheses, so .123 gets picked up instead of .pdf.

The fix: when the multi-dot approach produces a truncated result (i.e. invalid characters were found), fall back to path.extname() so the actual last extension is used.

Single-dot filenames and multi-dot filenames with no invalid characters are unaffected.

Fixes #980

…hars

When keepExtensions is true, filenames like "test(.123).pdf" or
"EERS 1.1-CUR.pdf" would produce incorrect extensions (".123" and ".1")
because _getExtension slices from the first dot and truncates at the
first invalid character.

When a multi-dot extension is truncated due to invalid characters, fall
back to path.extname() so the actual last extension is used instead.

Fixes node-formidable#980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specific file names cause the extension to not be set correctly with options.keepExtensions "test(.123).pdf"

1 participant