fix: escape "$" character to avoid bash interpreting (#884)
This commit is contained in:
parent
5655a90a28
commit
041c0427bb
|
@ -270,7 +270,7 @@ fn get_current_branch(repository: &Repository) -> Option<String> {
|
||||||
shorthand.map(std::string::ToString::to_string)
|
shorthand.map(std::string::ToString::to_string)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Shell {
|
pub enum Shell {
|
||||||
Bash,
|
Bash,
|
||||||
Fish,
|
Fish,
|
||||||
|
|
|
@ -191,18 +191,17 @@ fn ansi_strings_modified(ansi_strings: Vec<ANSIString>, shell: Shell) -> Vec<ANS
|
||||||
_ => x.to_string(),
|
_ => x.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MAYBE_ESCAPE_END => {
|
MAYBE_ESCAPE_END if escaped => {
|
||||||
if escaped {
|
escaped = false;
|
||||||
escaped = false;
|
match shell {
|
||||||
match shell {
|
Shell::Bash => String::from("m\u{5c}\u{5d}"), // => m\]
|
||||||
Shell::Bash => String::from("m\u{5c}\u{5d}"), // => m\]
|
Shell::Zsh => String::from("m\u{25}\u{7d}"), // => m%}
|
||||||
Shell::Zsh => String::from("m\u{25}\u{7d}"), // => m%}
|
_ => x.to_string(),
|
||||||
_ => x.to_string(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
x.to_string()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// escape the $ character to avoid $() code injection on bash shell,
|
||||||
|
// see #658 for more
|
||||||
|
'$' if Shell::Bash == shell => String::from("\\$"),
|
||||||
_ => x.to_string(),
|
_ => x.to_string(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Reference in New Issue