You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2020/10/01 19:38:25 UTC
[sling-org-apache-sling-scripting-sightly-compiler] branch master
updated: SLING-9783 - The HTL compiler will trigger a NPE if a null value
should be written into an HTML attribute
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler.git
The following commit(s) were added to refs/heads/master by this push:
new dba0f3d SLING-9783 - The HTL compiler will trigger a NPE if a null value should be written into an HTML attribute
dba0f3d is described below
commit dba0f3de73640621e4b3776351377b99f0f1b510
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Oct 1 21:37:59 2020 +0200
SLING-9783 - The HTL compiler will trigger a NPE if a null value should be written into an HTML attribute
* checked if the passed values in the context of attributes are not null
* performed some Yoda comparisons in cases where attribute values could be null
* updated the io.sightly.tck which provides additional tests for attributes to which
null values can be passed
---
.../sling/scripting/sightly/impl/html/dom/MarkupHandler.java | 10 +++++++---
.../sling/scripting/sightly/impl/plugin/AttributePlugin.java | 6 +++---
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java b/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java
index d3c5b10..a2767d4 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java
@@ -241,8 +241,12 @@ public class MarkupHandler {
shouldDisplayAttr,
new BinaryOperation(
BinaryOperator.AND,
- new BinaryOperation(BinaryOperator.NEQ, StringConstant.EMPTY, new Identifier(attrValue)),
- new BinaryOperation(BinaryOperator.NEQ, BooleanConstant.FALSE, new Identifier(attrValue))
+ new BinaryOperation(BinaryOperator.NEQ, NullLiteral.INSTANCE, new Identifier(attrValue)),
+ new BinaryOperation(
+ BinaryOperator.AND,
+ new BinaryOperation(BinaryOperator.NEQ, StringConstant.EMPTY, new Identifier(attrValue)),
+ new BinaryOperation(BinaryOperator.NEQ, BooleanConstant.FALSE, new Identifier(attrValue))
+ )
)
)
);
@@ -252,7 +256,7 @@ public class MarkupHandler {
emitAttributeStart(name); //write("attrName");
invoke.beforeAttributeValue(stream, name, node);
stream.write(new VariableBinding.Start(isTrueVar, //isTrueAttr = (attrValue == true)
- new BinaryOperation(BinaryOperator.EQ, new Identifier(attrValue), BooleanConstant.TRUE)));
+ new BinaryOperation(BinaryOperator.EQ, BooleanConstant.TRUE, new Identifier(attrValue))));
stream.write(new Conditional.Start(isTrueVar, false)); //if (!isTrueAttr)
emitAttributeValueStart(quoteChar); // write("='");
if (!alreadyEscaped) {
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java b/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java
index a0ef200..b5b92a1 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java
@@ -186,8 +186,8 @@ public class AttributePlugin extends AbstractPlugin {
private void emitWrite(PushStream stream) {
stream.write(new VariableBinding.Start(isTrueValue,
new BinaryOperation(BinaryOperator.EQ,
- new Identifier(attrValue),
- BooleanConstant.TRUE)));
+ BooleanConstant.TRUE,
+ new Identifier(attrValue))));
stream.write(new Conditional.Start(isTrueValue, false));
stream.write(new OutText("=\""));
stream.write(new OutputVariable(escapedAttrValue));
@@ -331,7 +331,7 @@ public class AttributePlugin extends AbstractPlugin {
String isTrueVar = compilerContext.generateVariable("isTrueAttr"); // holds the comparison (attrValue == true)
stream.write(new VariableBinding.Start(isTrueVar, //isTrueAttr = (attrContent == true)
- new BinaryOperation(BinaryOperator.EQ, new Identifier(attrContentVar), BooleanConstant.TRUE)));
+ new BinaryOperation(BinaryOperator.EQ, BooleanConstant.TRUE, new Identifier(attrContentVar))));
stream.write(new Conditional.Start(isTrueVar, false)); //if (!isTrueAttr)
stream.write(new OutText("=\""));