GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11124
Closed
yangadam wants to merge 1 commit into
Closed
GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11124yangadam wants to merge 1 commit into
yangadam wants to merge 1 commit into
Conversation
…ry wildcard paths
Change `lastIndex > 0` to `lastIndex >= 0` in `SftpSession.doList()` so
that root-level paths like `/*` are correctly split into directory and
file components. Previously, `lastIndexOf('/')` returning `0` was not
handled, causing the entire path to be treated as a directory name.
Fixes: spring-projectsgh-11121
Signed-off-by: Adam Yang <yangmm.adam@gmail.com>
Author
|
@artembilan can you help review this change? |
Member
|
Closing in favor of: #11122 I said on issue that the fix might be requested against |
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.
Summary
SftpSession.listNames("/*")throwsSftpException: SSH_FX_NO_SUCH_FILEwhen listing files in the root directory using a wildcard pattern.In
SftpSession.doList(), the path parsing useslastIndexOf('/')to split the directory and file parts. For root-level paths like/*,lastIndexOf('/')returns0, but the condition checkslastIndex > 0, which excludes index0. This means the path is never split —remoteDirstays as/*andremoteFilestaysnull, causing the SFTP client to try to open/*as a literal directory name.Bug introduced in 6.0.0.
Changes
lastIndex > 0tolastIndex >= 0inSftpSession.doList()so root directory paths are correctly parsedlsRootWildcard()that reproduces the issue and verifies the fixFixes: gh-11121