fix: fall back to path.extname when multi-dot extension has invalid chars#1070
Open
ordinary9843 wants to merge 1 commit intonode-formidable:masterfrom
Open
fix: fall back to path.extname when multi-dot extension has invalid chars#1070ordinary9843 wants to merge 1 commit intonode-formidable:masterfrom
ordinary9843 wants to merge 1 commit intonode-formidable:masterfrom
Conversation
…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
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.
When
keepExtensions: trueis set, filenames containing special characters like parentheses cause the wrong extension to be stored.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. Fortest(.123).pdf, the first dot falls inside the parentheses, so.123gets 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