add glob pattern support for known_hosts#15508
Conversation
|
Oops, fixing the failing tests... (edit: fixed) |
fb2c996 to
09ae8fe
Compare
src/cargo/sources/git/known_hosts.rs
Outdated
| regex::escape(&pattern.replace("*", ",,,,").replace("?", ";;;;")) | ||
| .replace(",,,,", ".*") | ||
| .replace(";;;;", "."); | ||
| if let Ok(regex) = Regex::new(®ex_pattern) { |
There was a problem hiding this comment.
Should we do anything on errors?
There was a problem hiding this comment.
Hmm, my thought is that if the pattern string could not be interpreted as glob pattern it's better to just pass glob matching.
There was a problem hiding this comment.
We could probably emit a tracing::warn! on failing cases.
09ae8fe to
786a78a
Compare
weihanglo
left a comment
There was a problem hiding this comment.
Thanks. Just one nit and we are good to go!
| } | ||
| for pattern in self.patterns.split(',') { | ||
| let pattern = pattern.to_lowercase(); | ||
| // FIXME: support * and ? wildcards |
There was a problem hiding this comment.
Was under the impression that this feature is tracked in #11577, but apparently not.
It seems like OpenSSH supports only * and ? wildcards. One caveat of using glob here is we provide more than we should. Anyway, it is good to catch up with the common format.
786a78a to
087285d
Compare
087285d to
e68d951
Compare
weihanglo
left a comment
There was a problem hiding this comment.
Great! Thanks for the contribution :)
Update cargo 5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95 2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000 - Stabilize doctest-xcompile (rust-lang/cargo#15462) - feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525) - chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520) - chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517) - add glob pattern support for known_hosts (rust-lang/cargo#15508) r? ghost
Update cargo 5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95 2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000 - Stabilize doctest-xcompile (rust-lang/cargo#15462) - feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525) - chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520) - chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517) - add glob pattern support for known_hosts (rust-lang/cargo#15508) r? ghost
What does this PR try to resolve?
This PR implements glob pattern match for known_hosts file. Hosts written with
*and?now matches correctly.Tests
Tests are added accordingly.
Miscs
This is my first time submitting PR, sorry if there's anything that's off although I've read the contributor guide.