From 132901bbe79a85e73810448f6d7a2ea4459f1d79 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 9 Feb 2018 01:07:12 -0500 Subject: [PATCH] fix escaping of sigils in component attribute values in SSR --- src/generators/server-side-rendering/visitors/Component.ts | 4 ++-- test/runtime/samples/sigil-component-attribute/Widget.html | 1 + test/runtime/samples/sigil-component-attribute/_config.js | 4 ++++ test/runtime/samples/sigil-component-attribute/main.html | 6 ++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/sigil-component-attribute/Widget.html create mode 100644 test/runtime/samples/sigil-component-attribute/_config.js create mode 100644 test/runtime/samples/sigil-component-attribute/main.html diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index 4843010fcb..2169ee9b6e 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -6,7 +6,7 @@ import { AppendTarget } from '../interfaces'; import { Node } from '../../../interfaces'; import getObject from '../../../utils/getObject'; import getTailSnippet from '../../../utils/getTailSnippet'; -import { stringify } from '../../../utils/stringify'; +import { escape, stringify } from '../../../utils/stringify'; export default function visitComponent( generator: SsrGenerator, @@ -14,7 +14,7 @@ export default function visitComponent( node: Node ) { function stringifyAttribute(chunk: Node) { - if (chunk.type === 'Text') return chunk.data; + if (chunk.type === 'Text') return escape(chunk.data); if (chunk.type === 'MustacheTag') { block.contextualise(chunk.expression); const { snippet } = chunk.metadata; diff --git a/test/runtime/samples/sigil-component-attribute/Widget.html b/test/runtime/samples/sigil-component-attribute/Widget.html new file mode 100644 index 0000000000..f0136f9405 --- /dev/null +++ b/test/runtime/samples/sigil-component-attribute/Widget.html @@ -0,0 +1 @@ +
{{value}}
diff --git a/test/runtime/samples/sigil-component-attribute/_config.js b/test/runtime/samples/sigil-component-attribute/_config.js new file mode 100644 index 0000000000..079bf3e9ab --- /dev/null +++ b/test/runtime/samples/sigil-component-attribute/_config.js @@ -0,0 +1,4 @@ +export default { + data: { foo: 'foo' }, + html: `
foo @ foo # foo
`, +}; diff --git a/test/runtime/samples/sigil-component-attribute/main.html b/test/runtime/samples/sigil-component-attribute/main.html new file mode 100644 index 0000000000..c9302309d2 --- /dev/null +++ b/test/runtime/samples/sigil-component-attribute/main.html @@ -0,0 +1,6 @@ + + +