use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.
the class ExpressionWrapperTest method testJoinOptionsRemoval.
@Test
public void testJoinOptionsRemoval() {
Interpolation interpolation = new Interpolation();
Map<String, ExpressionNode> options = new HashMap<>();
options.put(JoinFilter.JOIN_OPTION, new StringConstant(";"));
List<ExpressionNode> array = new ArrayList<>();
array.add(new NumericConstant(0));
array.add(new NumericConstant(1));
interpolation.addExpression(new Expression(new ArrayLiteral(array), options));
ExpressionWrapper wrapper = new ExpressionWrapper(filters);
Expression result = wrapper.transform(interpolation, MarkupContext.TEXT, ExpressionContext.TEXT);
List<ExpressionNode> xssArguments = runOptionsAndXSSAssertions(result, 0);
RuntimeCall join = (RuntimeCall) xssArguments.get(0);
assertEquals(RuntimeFunction.JOIN, join.getFunctionName());
}
use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.
the class IncludePlugin method invoke.
@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
return new DefaultPluginInvoke() {
@Override
public void beforeChildren(PushStream stream) {
String includedContentVar = compilerContext.generateVariable("includedResult");
String pathVar = compilerContext.generateVariable("includePath");
stream.write(new VariableBinding.Start(pathVar, expression.getRoot()));
stream.write(new VariableBinding.Start(includedContentVar, new RuntimeCall(RuntimeFunction.INCLUDE, new Identifier(pathVar), new MapLiteral(expression.getOptions()))));
stream.write(new OutputVariable(includedContentVar));
//end includedContentVar
stream.write(VariableBinding.END);
//end pathVar
stream.write(VariableBinding.END);
Patterns.beginStreamIgnore(stream);
}
@Override
public void afterChildren(PushStream stream) {
Patterns.endStreamIgnore(stream);
}
};
}
use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.
the class ExpressionWrapperTest method testFormatOptionsRemoval.
@Test
public void testFormatOptionsRemoval() {
Interpolation interpolation = new Interpolation();
Map<String, ExpressionNode> options = new HashMap<>();
List<ExpressionNode> formatArray = new ArrayList<>();
formatArray.add(new StringConstant("John"));
formatArray.add(new StringConstant("Doe"));
options.put(FormatFilter.FORMAT_OPTION, new ArrayLiteral(formatArray));
interpolation.addExpression(new Expression(new StringConstant("Hello {0} {1}"), options));
ExpressionWrapper wrapper = new ExpressionWrapper(filters);
Expression result = wrapper.transform(interpolation, MarkupContext.TEXT, ExpressionContext.TEXT);
List<ExpressionNode> xssArguments = runOptionsAndXSSAssertions(result, 0);
RuntimeCall format = (RuntimeCall) xssArguments.get(0);
assertEquals(RuntimeFunction.FORMAT, format.getFunctionName());
}
use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.
the class ExpressionWrapperTest method runOptionsAndXSSAssertions.
private List<ExpressionNode> runOptionsAndXSSAssertions(Expression result, int expectedOptions) {
assertEquals("Options map size for expression after processing is different from expected.", expectedOptions, result.getOptions().size());
RuntimeCall xss = (RuntimeCall) result.getRoot();
assertEquals("Expected XSS escaping applied to expression.", RuntimeFunction.XSS, xss.getFunctionName());
return xss.getArguments();
}
use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.
the class ExpressionReducer method evaluate.
@Override
public EvalResult evaluate(RuntimeCall runtimeCall) {
List<ExpressionNode> nodes = new ArrayList<>();
for (ExpressionNode node : runtimeCall.getArguments()) {
EvalResult result = eval(node);
nodes.add(result.getNode());
}
return EvalResult.nonConstant(new RuntimeCall(runtimeCall.getFunctionName(), nodes));
}
Aggregations