From 05a7a262c3e6245cededb12b854b8f587607948b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 2 Jun 2017 22:46:28 -0400 Subject: [PATCH] also escape back-ticks and backslashes in text nodes in SSR code (#616) --- src/generators/server-side-rendering/visitors/Text.ts | 4 ++-- test/runtime/samples/escape-template-literals/_config.js | 3 +++ test/runtime/samples/escape-template-literals/main.html | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/escape-template-literals/_config.js create mode 100644 test/runtime/samples/escape-template-literals/main.html diff --git a/src/generators/server-side-rendering/visitors/Text.ts b/src/generators/server-side-rendering/visitors/Text.ts index 3d119ff6be..0d8d539df3 100644 --- a/src/generators/server-side-rendering/visitors/Text.ts +++ b/src/generators/server-side-rendering/visitors/Text.ts @@ -3,5 +3,5 @@ import Block from '../Block'; import { Node } from '../../../interfaces'; export default function visitText ( generator: SsrGenerator, block: Block, node: Node ) { - generator.append( node.data.replace( /\${/g, '\\${' ) ); -} \ No newline at end of file + generator.append( node.data.replace( /(\${|`|\\)/g, '\\$1' ) ); +} diff --git a/test/runtime/samples/escape-template-literals/_config.js b/test/runtime/samples/escape-template-literals/_config.js new file mode 100644 index 0000000000..df22784ba7 --- /dev/null +++ b/test/runtime/samples/escape-template-literals/_config.js @@ -0,0 +1,3 @@ +export default { + html: '`${foo}\\n`' +}; diff --git a/test/runtime/samples/escape-template-literals/main.html b/test/runtime/samples/escape-template-literals/main.html new file mode 100644 index 0000000000..4705d114d2 --- /dev/null +++ b/test/runtime/samples/escape-template-literals/main.html @@ -0,0 +1 @@ +`${foo}\n`