diff options
author | Luca Rinaldi <lucarin@protonmail.com> | 2020-01-28 19:55:16 +0100 |
---|---|---|
committer | Matan Kushner <hello@matchai.dev> | 2020-01-28 13:55:16 -0500 |
commit | 041c0427bb53901a208c363dd32209ad75ca4cf3 (patch) | |
tree | b5095ef23c23fb7083c0260b26e72978bf76e572 | |
parent | 5655a90a28e2a286ae763c9fa7afe88c09a77920 (diff) |
fix: escape "$" character to avoid bash interpreting (#884)
-rw-r--r-- | src/context.rs | 2 | ||||
-rw-r--r-- | src/module.rs | 19 |
2 files changed, 10 insertions, 11 deletions
diff --git a/src/context.rs b/src/context.rs index 460ede159..ce2002066 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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, diff --git a/src/module.rs b/src/module.rs index f09c6e5df..1768d6b2f 100644 --- a/src/module.rs +++ b/src/module.rs @@ -191,18 +191,17 @@ fn ansi_strings_modified(ansi_strings: Vec<ANSIString>, shell: Shell) -> Vec<ANS _ => x.to_string(), } } - 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() + 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(), } } + // escape the $ character to avoid $() code injection on bash shell, + // see #658 for more + '$' if Shell::Bash == shell => String::from("\\$"), _ => x.to_string(), }) .collect(); |