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 {