use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation in project sling by apache.
the class ExpressionWrapperTest method testI18nOptionsRemoval.
@Test
public void testI18nOptionsRemoval() {
Interpolation interpolation = new Interpolation();
Map<String, ExpressionNode> options = new HashMap<>();
options.put(I18nFilter.HINT_OPTION, new StringConstant("hint"));
options.put(I18nFilter.LOCALE_OPTION, new StringConstant("de"));
options.put(I18nFilter.I18N_OPTION, NullLiteral.INSTANCE);
interpolation.addExpression(new Expression(new StringConstant("hello"), options));
ExpressionWrapper wrapper = new ExpressionWrapper(filters);
Expression result = wrapper.transform(interpolation, MarkupContext.TEXT, ExpressionContext.TEXT);
List<ExpressionNode> xssArguments = runOptionsAndXSSAssertions(result, 1);
RuntimeCall i18n = (RuntimeCall) xssArguments.get(0);
assertEquals("Expected to I18n runtime function call.", RuntimeFunction.I18N, i18n.getFunctionName());
}
use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation in project sling by apache.
the class MarkupHandler method outText.
private void outText(String content, MarkupContext context) {
Interpolation interpolation = expressionParser.parseInterpolation(content);
if (context == null) {
interpolation = requireContext(interpolation);
}
String text = tryAsSimpleText(interpolation);
if (text != null) {
out(text);
} else {
outExprNode(expressionWrapper.transform(interpolation, context, ExpressionContext.TEXT).getRoot());
}
}
use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation in project sling by apache.
the class ExpressionWrapperTest method testURIOptionsRemoval.
@Test
public void testURIOptionsRemoval() {
Interpolation interpolation = new Interpolation();
Map<String, ExpressionNode> options = new HashMap<>();
options.put(URIManipulationFilter.SCHEME, new StringConstant("https"));
options.put(URIManipulationFilter.DOMAIN, new StringConstant("www.example.org"));
options.put(URIManipulationFilter.PREPEND_PATH, new StringConstant("/before"));
options.put(URIManipulationFilter.PATH, new StringConstant("/path"));
options.put(URIManipulationFilter.APPEND_PATH, new StringConstant("/after"));
List<ExpressionNode> selectors = new ArrayList<>();
selectors.add(new StringConstant("a"));
selectors.add(new StringConstant("b"));
options.put(URIManipulationFilter.SELECTORS, new ArrayLiteral(selectors));
options.put(URIManipulationFilter.EXTENSION, new StringConstant("html"));
options.put(URIManipulationFilter.PREPEND_SUFFIX, new StringConstant("/pre"));
options.put(URIManipulationFilter.APPEND_SUFFIX, new StringConstant("/after"));
options.put(URIManipulationFilter.FRAGMENT, new StringConstant("rewrite"));
Map<String, ExpressionNode> query = new HashMap<>();
query.put("q", new StringConstant("sightly"));
query.put("array", new ArrayLiteral(new ArrayList<ExpressionNode>() {
{
add(new NumericConstant(1));
add(new NumericConstant(2));
add(new NumericConstant(3));
}
}));
options.put(URIManipulationFilter.QUERY, new MapLiteral(query));
options.put(URIManipulationFilter.REMOVE_QUERY, new StringConstant("array"));
interpolation.addExpression(new Expression(new StringConstant("http://www.example.com/resource.selector.extension/suffix#fragment?param=value"), 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.URI_MANIPULATION, join.getFunctionName());
}
use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation 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.impl.compiler.frontend.Interpolation in project sling by apache.
the class MarkupHandler method requireContext.
private Interpolation requireContext(Interpolation interpolation) {
Interpolation result = new Interpolation();
for (Fragment fragment : interpolation.getFragments()) {
Fragment addedFragment;
if (fragment.isString()) {
addedFragment = fragment;
} else {
if (fragment.getExpression().containsOption(Syntax.CONTEXT_OPTION)) {
addedFragment = fragment;
} else {
String currentTag = currentElementTag();
String warningMessage = String.format("Element %s requires that all expressions have an explicit context specified. " + "The expression will be replaced with an empty string.", currentTag);
stream.warn(new PushStream.StreamMessage(warningMessage, fragment.getExpression().getRawText()));
addedFragment = new Fragment.Expr(new Expression(StringConstant.EMPTY));
}
}
result.addFragment(addedFragment);
}
return result;
}
Aggregations