Merge pull request #188 from sinkuu/astescape
Fix XML attribute escaping in AST
This commit is contained in:
commit
9f6688a306
14
astprinter.d
14
astprinter.d
|
@ -133,7 +133,7 @@ class XMLPrinter : ASTVisitor
|
||||||
output.writeln("<assignExpression>");
|
output.writeln("<assignExpression>");
|
||||||
else
|
else
|
||||||
output.writeln("<assignExpression operator=\"",
|
output.writeln("<assignExpression operator=\"",
|
||||||
xmlEscape(str(assignExpression.operator)), "\">");
|
xmlAttributeEscape(str(assignExpression.operator)), "\">");
|
||||||
assignExpression.accept(this);
|
assignExpression.accept(this);
|
||||||
output.writeln("</assignExpression>");
|
output.writeln("</assignExpression>");
|
||||||
}
|
}
|
||||||
|
@ -995,7 +995,7 @@ class XMLPrinter : ASTVisitor
|
||||||
override void visit(const RelExpression relExpression)
|
override void visit(const RelExpression relExpression)
|
||||||
{
|
{
|
||||||
output.writeln("<relExpression operator=\"",
|
output.writeln("<relExpression operator=\"",
|
||||||
xmlEscape(str(relExpression.operator)), "\">");
|
xmlAttributeEscape(str(relExpression.operator)), "\">");
|
||||||
output.writeln("<left>");
|
output.writeln("<left>");
|
||||||
relExpression.left.accept(this);
|
relExpression.left.accept(this);
|
||||||
output.writeln("</left>");
|
output.writeln("</left>");
|
||||||
|
@ -1035,7 +1035,7 @@ class XMLPrinter : ASTVisitor
|
||||||
override void visit(const ShiftExpression shiftExpression)
|
override void visit(const ShiftExpression shiftExpression)
|
||||||
{
|
{
|
||||||
output.writeln("<shiftExpression operator=\"",
|
output.writeln("<shiftExpression operator=\"",
|
||||||
xmlEscape(str(shiftExpression.operator)), "\">");
|
xmlAttributeEscape(str(shiftExpression.operator)), "\">");
|
||||||
output.writeln("<left>");
|
output.writeln("<left>");
|
||||||
shiftExpression.left.accept(this);
|
shiftExpression.left.accept(this);
|
||||||
output.writeln("</left>");
|
output.writeln("</left>");
|
||||||
|
@ -1340,7 +1340,7 @@ class XMLPrinter : ASTVisitor
|
||||||
auto app = appender!string();
|
auto app = appender!string();
|
||||||
auto formatter = new Formatter!(typeof(app))(app);
|
auto formatter = new Formatter!(typeof(app))(app);
|
||||||
formatter.format(type);
|
formatter.format(type);
|
||||||
output.writeln("<type pretty=\"", app.data, "\">");
|
output.writeln("<type pretty=\"", xmlAttributeEscape(app.data), "\">");
|
||||||
type.accept(this);
|
type.accept(this);
|
||||||
output.writeln("</type>");
|
output.writeln("</type>");
|
||||||
}
|
}
|
||||||
|
@ -1513,6 +1513,12 @@ class XMLPrinter : ASTVisitor
|
||||||
return s.translate(['<' : "<", '>' : ">", '&' : "&"]);
|
return s.translate(['<' : "<", '>' : ">", '&' : "&"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string xmlAttributeEscape(string s)
|
||||||
|
{
|
||||||
|
return s.translate(['<' : "<", '>' : ">", '&' : "&",
|
||||||
|
'\"' : """, '\'' : "'"]);
|
||||||
|
}
|
||||||
|
|
||||||
private void writeDdoc(string comment)
|
private void writeDdoc(string comment)
|
||||||
{
|
{
|
||||||
if (comment is null) return;
|
if (comment is null) return;
|
||||||
|
|
Loading…
Reference in New Issue