Skip to content

Commit 553eceb

Browse files
committed
Do not escape $ before backslash.
1 parent 91e2de9 commit 553eceb

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ fn translate_path_to_win(line: &[u8]) -> Vec<u8> {
167167

168168
fn escape_dollar_but_not_env_cmds(haystack: &str) -> String {
169169
static DOLLAR_AND_FOLLOWING_RE: LazyLock<StrRegex> = LazyLock::new(|| {
170-
StrRegex::new(r"\$([\(\)\w]*)").expect("Failed to compile DOLLAR_AND_FOLLOWING_RE regex")
170+
StrRegex::new(r"\$([\(\)\w\\]*)").expect("Failed to compile DOLLAR_AND_FOLLOWING_RE regex")
171171
});
172172
let mut escaped = String::with_capacity(haystack.len());
173173
let mut last_match = 0;
174174
for m in DOLLAR_AND_FOLLOWING_RE.find_iter(haystack) {
175175
escaped.push_str(&haystack[last_match..m.start()]);
176176
let m_str = m.as_str();
177-
if m_str.starts_with("$(wslpath")
177+
if m_str.starts_with("$\\")
178+
|| m_str.starts_with("$(wslpath")
178179
|| m_str.starts_with("$(env")
179180
|| m_str.starts_with("$(printenv")
180181
{
@@ -863,6 +864,14 @@ mod tests {
863864
);
864865
}
865866

867+
#[test]
868+
fn do_not_escape_dollar_in_pathname() {
869+
assert_eq!(
870+
format_argument(r##"\\wsl$\Debian\home"##.to_string()),
871+
r##""$(wslpath '\\wsl$\Debian\home')""##
872+
);
873+
}
874+
866875
#[test]
867876
fn git_url_translation() {
868877
// URLs with ssh, git, http[s] or ftp[s] prefix should not be translated

0 commit comments

Comments
 (0)