Skip to content

Commit 160cc71

Browse files
committed
Recursively replace
1 parent d65dcd7 commit 160cc71

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/shell/execute.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3+
use std::borrow::Cow;
34
use std::collections::HashMap;
45
use std::ffi::OsStr;
56
use std::ffi::OsString;
@@ -862,17 +863,21 @@ fn evaluate_word_parts(
862863

863864
// when globstar is disabled, replace ** with * so it doesn't match
864865
// across directory boundaries (the glob crate always treats ** as recursive)
865-
let pattern_text = if !options.contains(ShellOptions::GLOBSTAR)
866+
let pattern_text: Cow<str> = if !options.contains(ShellOptions::GLOBSTAR)
866867
&& current_text.contains("**")
867868
{
868-
// replace ** with * to disable recursive matching
869-
current_text.replace("**", "*")
869+
// repeatedly replace ** with * to handle cases like *** -> ** -> *
870+
let mut result = current_text.clone();
871+
while result.contains("**") {
872+
result = result.replace("**", "*");
873+
}
874+
Cow::Owned(result)
870875
} else {
871-
current_text.clone()
876+
Cow::Borrowed(&current_text)
872877
};
873878

874879
let pattern = if is_absolute {
875-
pattern_text.clone()
880+
pattern_text.into_owned()
876881
} else {
877882
format!("{}/{}", cwd.display(), pattern_text)
878883
};

0 commit comments

Comments
 (0)