mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
implement triples in SSR compiler, and escape HTML for regular tags
This commit is contained in:
parent
23b7759160
commit
c8b232f431
@ -219,6 +219,11 @@ export default function compile ( parsed, source, { filename }) {
|
||||
},
|
||||
|
||||
MustacheTag ( node ) {
|
||||
const { snippet } = contextualise( node.expression ); // TODO use snippet, for sourcemap support
|
||||
return '${__escape( String( ' + snippet + ') )}';
|
||||
},
|
||||
|
||||
RawMustacheTag ( node ) {
|
||||
const { snippet } = contextualise( node.expression ); // TODO use snippet, for sourcemap support
|
||||
return '${' + snippet + '}';
|
||||
},
|
||||
@ -381,6 +386,18 @@ export default function compile ( parsed, source, { filename }) {
|
||||
exports.renderCss = function () {
|
||||
${renderCssStatements.join( '\n\n' )}
|
||||
};
|
||||
|
||||
var escaped = {
|
||||
'"': '"',
|
||||
"'": '&39;',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>'
|
||||
};
|
||||
|
||||
function __escape ( html ) {
|
||||
return html.replace( /["'&<>]/g, match => escaped[ match ] );
|
||||
}
|
||||
` );
|
||||
|
||||
const rendered = topLevelStatements.join( '\n\n' );
|
||||
|
@ -0,0 +1 @@
|
||||
<p>this should be <em>escaped</em> & so should &39;this&39;</p>
|
@ -0,0 +1 @@
|
||||
<p>this should be <em>escaped</em> & so should &39;this&39;</p>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": "<p>this should be <em>escaped</em> & so should 'this'</p>"
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{foo}}
|
1
test/server-side-rendering/triple/_actual.html
Normal file
1
test/server-side-rendering/triple/_actual.html
Normal file
@ -0,0 +1 @@
|
||||
<div><p>html</p></div>
|
1
test/server-side-rendering/triple/_expected.html
Normal file
1
test/server-side-rendering/triple/_expected.html
Normal file
@ -0,0 +1 @@
|
||||
<div><p>html</p></div>
|
11
test/server-side-rendering/triple/main.html
Normal file
11
test/server-side-rendering/triple/main.html
Normal file
@ -0,0 +1,11 @@
|
||||
<div>{{{triple}}}</div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
triple: '<p>html</p>'
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user