fix: escape "$" character to avoid bash interpreting (#884)

This commit is contained in:
Luca Rinaldi 2020-01-28 19:55:16 +01:00 committed by Matan Kushner
parent 5655a90a28
commit 041c0427bb
2 changed files with 10 additions and 11 deletions

View File

@ -270,7 +270,7 @@ fn get_current_branch(repository: &Repository) -> Option<String> {
shorthand.map(std::string::ToString::to_string)
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum Shell {
Bash,
Fish,

View File

@ -191,18 +191,17 @@ fn ansi_strings_modified(ansi_strings: Vec<ANSIString>, shell: Shell) -> Vec<ANS
_ => x.to_string(),
}
}
MAYBE_ESCAPE_END => {
if escaped {
MAYBE_ESCAPE_END if escaped => {
escaped = false;
match shell {
Shell::Bash => String::from("m\u{5c}\u{5d}"), // => m\]
Shell::Zsh => String::from("m\u{25}\u{7d}"), // => m%}
_ => 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(),
})
.collect();