Skip to content

fix: preserve literal paths in Glob - #665

Merged
puellanivis merged 2 commits into
pkg:masterfrom
hoobnn:fix/glob-literal-paths
Oct 26, 2026
Merged

puellanivis merged 2 commits into
pkg:masterfrom
hoobnn:fix/glob-literal-paths

Conversation

@hoobnn

@hoobnn hoobnn commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #531.

For an existing directory, Client.Glob("/home/") currently returns /home/home. The literal-path branch rebuilds the result from the split pattern and FileInfo.Name(), duplicating the final component when the pattern ends in a slash.

Return the original pattern after Lstat confirms it exists. This matches path/filepath.Glob, which returns the pattern unchanged in this case, as noted in the issue. This also preserves leading ./, ./.. elements and repeated separators. Wildcard patterns are unaffected.

The new test runs a client against an in-memory RequestServer over net.Pipe. 7 of its 12 literal-path cases fail without this change.

Tested on macOS (Go 1.27.1): go test -race ./..., plus the existing Glob integration tests against OpenSSH's sftp-server.

I used OpenAI Codex and Claude Code to investigate the issue, write the fix and tests, and run the checks. I reviewed the code and this description myself.

Assisted by Claude Code

@puellanivis

Copy link
Copy Markdown
Collaborator

Please do not use Co-Authored-By to indicate an AI model. They are—as a matter of law—incapable of being an author.

I’m recommending the use of Assisted-by advocated by the Linux kernel https://docs.kernel.org/process/coding-assistants.html

@hoobnn
hoobnn force-pushed the fix/glob-literal-paths branch from 37560f0 to 681938c Compare October 7, 2026 21:55
@hoobnn
hoobnn force-pushed the fix/glob-literal-paths branch from 681938c to f57bc63 Compare October 20, 2026 02:24
@hoobnn

hoobnn commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer. I've replaced the Co-Authored-By trailers with Assisted-by: tags in the AGENT:MODEL form and force-pushed.

Comment thread match_test.go Resolved
Assisted-by: Codex:gpt-6.1-sol
Assisted-by: Claude:claude-opus-5-5
@hoobnn
hoobnn force-pushed the fix/glob-literal-paths branch from f57bc63 to a30b8fb Compare October 25, 2026 14:44
Comment thread match_test.go Resolved
Assisted-by: Claude:claude-opus-5-5
@puellanivis
puellanivis merged commit 519dbfa into pkg:master Oct 26, 2026
4 checks passed
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.

sftp.Glob returns incorrect path of found file or dir

2 participants