aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/parse/mod.rs7
-rw-r--r--src/parse/test.rs15
2 files changed, 22 insertions, 0 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 4806421..4c19c96 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -470,6 +470,13 @@ impl Parse for ExpString {
let x = b.peek();
if escaping {
+ let x = match x {
+ b'n' => b'\n',
+ b'r' => b'\r',
+ b't' => b'\t',
+ b'e' => 0x1b, // escape
+ _ => x,
+ };
add_char(p, x);
escaping = false;
b.adv();
diff --git a/src/parse/test.rs b/src/parse/test.rs
index ca57e75..92124b0 100644
--- a/src/parse/test.rs
+++ b/src/parse/test.rs
@@ -94,3 +94,18 @@ fn variable_with_defaults() {
pipes([cmd([str([var_default(b"x", estr(b"y"))])])]),
);
}
+
+#[test]
+fn escape_newline() {
+ parse_test(parse(b"\"\\n\""), pipes([cmd([estr(b"\n")])]));
+}
+
+#[test]
+fn escape_carriage_return() {
+ parse_test(parse(b"\"\\r\""), pipes([cmd([estr(b"\r")])]));
+}
+
+#[test]
+fn escape_tab() {
+ parse_test(parse(b"\"\\t\""), pipes([cmd([estr(b"\t")])]));
+}