Repository navigation
Correct extension handling for dotfiles in paths - #37463
Open
sandeep780049 wants to merge 1 commit into
Open
sandeep780049 wants to merge 1 commit into
sandeep780049 wants to merge 1 commit into
Conversation
getFilenameExtension() and stripFilenameExtension() measured the last dot against the entire path, which misclassified dotfiles: a leading dot in "my/path/.hidden" was treated as an extension separator and ".hidden" was returned as the extension. The methods now evaluate the dot position against the filename alone, and a leading dot in the filename is never treated as an extension separator. Closes spring-projectsgh-37462 Signed-off-by: Sandeep Kumar <sandeep780049@users.noreply.github.com>
This branch has not been deployed
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.
Motivation
StringUtils.getFilenameExtension(String)andStringUtils.stripFilenameExtension(String)search for the last'.'in the entire path rather than in the filename. As a result, a dotfile (a filename that starts with a dot and has no extension) is misclassified:This affects consumers such as
MediaTypeFactory,StandardScriptEvaluator, resource version strategies, andResourceHttpRequestHandler, which can treat.gitignore-style resources as if they had a file extension.Closes gh-37462
Solution
Both methods now resolve the filename first and look up the last dot within the filename only. A leading dot in the filename (
extIndex <= 0) is never treated as an extension separator:Behavior for all existing cases, including
"myfile."(empty extension),"my/dir/myfile.txt", and paths whose folder separator appears after the last dot, is unchanged.Testing
getFilenameExtensioncases:".hidden"and"myPath/.hidden".stripFilenameExtensioncases:".hidden"and"mypath/.hidden"../gradlew :spring-core:test --tests org.springframework.util.StringUtilsTests— 94 tests, 0 failures../gradlew :spring-core:checkstyleMainpasses.Signed-off-by: Sandeep Kumar sandeep780049@users.noreply.github.com