diff --git a/src/ambr.rs b/src/ambr.rs index 011072713..838a7f063 100644 --- a/src/ambr.rs +++ b/src/ambr.rs @@ -5,7 +5,7 @@ use amber::pipeline_finder::PipelineFinder; use amber::pipeline_matcher::PipelineMatcher; use amber::pipeline_replacer::PipelineReplacer; use amber::pipeline_sorter::PipelineSorter; -use amber::util::{as_secsf64, decode_error, exit, read_from_file}; +use amber::util::{as_secsf64, decode_error, exit, handle_escape, read_from_file}; use crossbeam::channel::unbounded; use lazy_static::lazy_static; use serde::Deserialize; @@ -379,7 +379,7 @@ fn main() { } } } else { - opt.keyword.into_bytes() + handle_escape(&opt.keyword).into_bytes() }; let replacement = if opt.rep_from_file { @@ -394,7 +394,7 @@ fn main() { } } } else { - opt.replacement.into_bytes() + handle_escape(&opt.replacement).into_bytes() }; // --------------------------------------------------------------------------------------------- diff --git a/src/ambs.rs b/src/ambs.rs index ed503719f..6540c1f28 100644 --- a/src/ambs.rs +++ b/src/ambs.rs @@ -5,7 +5,7 @@ use amber::pipeline_finder::PipelineFinder; use amber::pipeline_matcher::PipelineMatcher; use amber::pipeline_printer::PipelinePrinter; use amber::pipeline_sorter::PipelineSorter; -use amber::util::{as_secsf64, decode_error, exit, read_from_file}; +use amber::util::{as_secsf64, decode_error, exit, handle_escape, read_from_file}; use crossbeam::channel::unbounded; use lazy_static::lazy_static; use serde::Deserialize; @@ -357,7 +357,7 @@ fn main() { } } } else { - opt.keyword.into_bytes() + handle_escape(&opt.keyword).into_bytes() }; // --------------------------------------------------------------------------------------------- diff --git a/src/util.rs b/src/util.rs index 637ae2ee2..7eca164cc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -97,6 +97,14 @@ pub fn exit(code: i32, console: &mut Console) -> ! { process::exit(code); } +pub fn handle_escape(text: &str) -> String { + let text = text.replace("\\n", "\n"); + let text = text.replace("\\r", "\r"); + let text = text.replace("\\t", "\t"); + let text = text.replace("\\\\", "\\"); + text +} + #[cfg(not(windows))] pub fn set_c_lflag(c_lflag: Option) { if let Ok(mut termios) = termios::Termios::from_fd(0) {