From 8dfa67a245b08a2c0ea1e6381c0086768470f317 Mon Sep 17 00:00:00 2001 From: Sean Doherty Date: Sat, 16 May 2026 17:15:00 -0500 Subject: [PATCH] Treat single dash as search path --- CHANGELOG.md | 1 + src/cli.rs | 4 ++++ tests/tests.rs | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e0ed1..458cd05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ## Bugfixes - Handle invalid working directories gracefully when using `--full-path`, see #1900 (@Xavrir). - Fire the "search pattern contains a path separator" diagnostic for any pattern containing `/`, not just patterns that happen to name an existing directory. Preserves the legacy Windows behaviour that also flags native `\` separators when the pattern resolves to a real directory. See #1873. +- Treat `-` as a literal search path when a directory with that name exists, see #849 (@Sean-Kenneth-Doherty). # 10.4.2 diff --git a/src/cli.rs b/src/cli.rs index 9c54d7c..638a042 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -712,6 +712,10 @@ impl Opts { } else if path == Path::new(".") { // Change "." to "./" as a workaround for https://github.com/BurntSushi/ripgrep/pull/2711 PathBuf::from("./") + } else if path == Path::new("-") { + // Prefix "-" so the underlying walker treats it as a path. + // See sharkdp/fd#849. + Path::new(".").join(path) } else { path.to_path_buf() } diff --git a/tests/tests.rs b/tests/tests.rs index aa0919c..0340cdd 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -459,6 +459,13 @@ fn test_explicit_root_path() { ); } +#[test] +fn test_single_dash_root_path() { + let te = TestEnv::new(&["-"], &["-/foo"]); + + te.assert_output(&[".", "-"], "./-/foo"); +} + /// Regex searches #[test] fn test_regex_searches() {