Don't escape for $!{}

This commit is contained in:
Patrick Steele-Idem 2015-12-29 15:26:33 -07:00
parent 257dd1f5c4
commit 8263c6aad4
7 changed files with 15 additions and 28 deletions

View File

@ -20,10 +20,7 @@ function isIEConditionalComment(comment) {
return ieConditionalCommentRegExp.test(comment);
}
function parseExpression(expression) {
// TODO Build an AST from the String expression
return expression;
}
var parseExpression = require('./util/parseExpression');
class Parser {
constructor(parserImpl) {
@ -122,7 +119,7 @@ class Parser {
name: attr.name,
value: isLiteral ?
builder.literal(attr.literalValue) :
parseExpression(attr.expression)
attr.expression == null ? undefined : parseExpression(attr.expression)
};
if (attr.argument) {
@ -171,9 +168,11 @@ class Parser {
handleBodyTextPlaceholder(expression, escape) {
this.prevTextNode = null;
var parsedExpression = parseExpression(expression);
var builder = this.context.builder;
var text = builder.text(expression, escape);
var text = builder.text(parsedExpression, escape);
this.parentNode.appendChild(text);
}

View File

@ -49,11 +49,13 @@ class Text extends Node {
}
} else {
let builder = codegen.builder;
// TODO Only escape if necessary
argument = builder.functionCall(
'escapeXml',
[argument]);
if (this.escape !== false) {
// TODO Only escape the parts that need to be escaped if it is a compound expression with static
// text parts
argument = builder.functionCall(
'escapeXml',
[argument]);
}
}
codegen.addWrite(argument);

View File

@ -1 +0,0 @@
<span>Welcome</span><span>Welcome</span><span>Welcome</span> &lt;Patrick><div title="&lt;span&gt;Welcome&lt;/span&gt; &lt;hello&gt;" data-name="&lt;Patrick&gt;"></div><div data-attr="Hello &lt;Patrick&gt; &lt;hello&gt;" data-nested-attr="&lt;Hello&gt; &lt;Patrick&gt; &lt;hello&gt;" data-nested-attr2="Hello &lt;John&gt; &lt;hello&gt;">Hello &lt;John>© &lt;hello> <START></div>

View File

@ -1,16 +0,0 @@
<var name="name" value="data.name"/>
<var name="welcome" value="data.welcome"/>
$!welcome
$!{welcome}
${xml:welcome}
$name
<div title="$welcome &lt;hello&gt;" data-name="$name"/>
<div data-attr="Hello $name &lt;hello&gt;">
<attr name="data-nested-attr">&lt;Hello> $name <![CDATA[<hello>]]></attr>
<attr name="data-nested-attr2" value="Hello &lt;John&gt; &lt;hello&gt;"/>
Hello &lt;John&gt;© <![CDATA[<hello>]]>
${startTag:START}
</div>

View File

@ -0,0 +1 @@
<span>Welcome</span>&lt;Patrick>

View File

@ -0,0 +1,2 @@
$!{data.welcome}
${data.name}