NIFI-16000: Allow spaces in FileUtils.getSanitizedFilename#11315
Open
mcgilman wants to merge 1 commit into
Open
NIFI-16000: Allow spaces in FileUtils.getSanitizedFilename#11315mcgilman wants to merge 1 commit into
mcgilman wants to merge 1 commit into
Conversation
Remove the space character from the invalid-character set so spaces are preserved rather than replaced with an underscore. No other normalization is performed, so leading, trailing, repeated, and interior spaces are kept exactly as supplied. This lets the asset-upload callers accept common valid filenames such as "driver (1).jar" that were previously rejected, while remaining backward compatible for names that contain no spaces. Add TestFileUtils covering the sanitization contract.
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.
Remove the space character from the invalid-character set so interior spaces are preserved, and normalize the result by collapsing whitespace runs to a single space and stripping leading/trailing whitespace and trailing dots. This lets the asset-upload callers accept common valid filenames such as "driver (1).jar" while still rejecting non-canonical names. Add TestFileUtils covering the sanitization contract.
Summary
NIFI-16000
FileUtils.getSanitizedFilename(String)treats the space character (code point32) as invalid and replaces it with an underscore. The space character is legal on every major file system (NTFS, ext4, APFS, etc.), so this is stricter than necessary.This matters because of how the method is consumed. Both
ConnectorResourceandParameterContextResourceuse it as a strict validation gate for the asset name supplied in theFilenamerequest header — they sanitize the supplied name and reject the request if the sanitized value differs from the original:Because any name containing a space is rewritten during sanitization, the equality check fails and the upload is rejected. As a result, common valid filenames cannot be uploaded as assets — e.g. a file produced by browser/OS download de-duplication such as
driver (1).jaris sanitized todriver_(1).jarand rejected with "... header contains an invalid file name."Changes
32) from the invalid-character set so spaces are preserved rather than replaced.TestFileUtilscovering the sanitization contract (null/empty, invalid-character replacement, spaces preserved, dots preserved).The change is backward compatible: any filename that contained no spaces is sanitized exactly as before. The only behavioral change is that the space character is now preserved instead of replaced, so filenames whose sole issue was a space are now accepted by the asset-upload callers instead of being rejected.
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation