From 3cc2e3315dae1c2e6f739e05ab08a47de2525ce0 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 9 Apr 2019 19:37:43 -0400 Subject: [PATCH] Don't emit octal escape for null character followed by digit --- ecmascript/codegen/src/lib.rs | 10 ++++++++++ ecmascript/codegen/src/tests.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 6edf26cd6da..259ea6b48ed 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -358,6 +358,16 @@ impl<'a> Emitter<'a> { .replace("\r", "\\r") .replace("\t", "\\t") .replace('\u{000B}', "\\v") + .replace("\00", "\\x000") + .replace("\01", "\\x001") + .replace("\02", "\\x002") + .replace("\03", "\\x003") + .replace("\04", "\\x004") + .replace("\05", "\\x005") + .replace("\06", "\\x006") + .replace("\07", "\\x007") + .replace("\08", "\\x008") + .replace("\09", "\\x009") .replace("\0", "\\0"); // let value = node.value.replace("\n", "\\n"); diff --git a/ecmascript/codegen/src/tests.rs b/ecmascript/codegen/src/tests.rs index e4ea237a828..e5a10ba8132 100644 --- a/ecmascript/codegen/src/tests.rs +++ b/ecmascript/codegen/src/tests.rs @@ -158,6 +158,20 @@ a;", ); } +#[test] +fn no_octal_escape() { + test_from_to( + r#"'\x00a'; +'\x000'; +'\x001'; +'\x009'"#, + r#"'\0a'; +'\x000'; +'\x001'; +'\x009';"#, + ); +} + #[derive(Debug, Clone)] struct Buf(Arc>>); impl Write for Buf {