use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation 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.impl.compiler.frontend.Interpolation in project sling by apache.
the class MarkupHandler method emitAttribute.
private void emitAttribute(String name, String content, char quoteChar, PluginInvoke invoke) {
invoke.beforeAttribute(stream, name);
if (content == null) {
emitSimpleTextAttribute(name, null, quoteChar, invoke);
} else {
Interpolation interpolation = expressionParser.parseInterpolation(content);
String text = tryAsSimpleText(interpolation);
if (text != null) {
emitSimpleTextAttribute(name, text, quoteChar, invoke);
} else {
emitExpressionAttribute(name, interpolation, quoteChar, invoke);
}
}
invoke.afterAttribute(stream, name);
}
use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation in project sling by apache.
the class MarkupHandler method attributeChecked.
private Interpolation attributeChecked(String attributeName, Interpolation interpolation) {
if (!MarkupUtils.isSensitiveAttribute(attributeName)) {
return interpolation;
}
Interpolation newInterpolation = new Interpolation();
for (Fragment fragment : interpolation.getFragments()) {
Fragment addedFragment = fragment;
if (fragment.isExpression()) {
Expression expression = fragment.getExpression();
if (!expression.containsOption(Syntax.CONTEXT_OPTION)) {
String warningMessage = String.format("Expressions within the value of attribute %s need to have an explicit context " + "option. The expression will be replaced with an empty string.", attributeName);
stream.warn(new PushStream.StreamMessage(warningMessage, expression.getRawText()));
addedFragment = new Fragment.Text("");
}
}
newInterpolation.addFragment(addedFragment);
}
return newInterpolation;
}
Aggregations