134
134
// Quoting <% and %>
135
135
assertEquals("hello <% world", evalAttr("hello <\\% world", '\"'));
136
136
assertEquals("hello %> world", evalAttr("hello %> world", '\"'));
138
// Test that the end of literal in EL expression is recognized in
139
// parseEL(), be it quoted with single or double quotes. That is, that
140
// AttributeParser correctly switches between parseLiteral and parseEL
143
// The test is based on the difference in how the '\' character is printed:
144
// when in parseLiteral \\${ will be printed as ${'\'}${, but if we are still
145
// inside of parseEL it will be printed as \${, thus preventing the EL
146
// expression that follows from being evaluated.
148
assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\'bar\'}\\\\${\'baz\'}", '\"'));
149
assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\\\"bar\\\"}\\\\${\'baz\'}", '\"'));
150
assertEquals("foo\\bar\\baz", evalAttr("${\\\"foo\\\"}\\\\${\'bar\'}\\\\${\\\"baz\\\"}", '\"'));
151
assertEquals("foo\\bar\\baz", evalAttr("${\"foo\"}\\\\${\\\'bar\\\'}\\\\${\"baz\"}", '\''));
139
public void testScriptExpressiinLiterals() {
154
public void testScriptExpressionLiterals() {
140
155
assertEquals(" \"hello world\" ", parseScriptExpression(
141
156
" \"hello world\" ", (char) 0));
142
157
assertEquals(" \"hello \\\"world\" ", parseScriptExpression(
149
164
ctx.setFunctionMapper(new FMapper());
150
165
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
151
166
ValueExpression ve = exprFactory.createValueExpression(ctx,
152
AttributeParser.getUnquoted(expression, quote, false, false),
167
AttributeParser.getUnquoted(expression, quote, false, false,
154
170
return (String) ve.getValue(ctx);
157
173
private String parseScriptExpression(String expression, char quote) {
158
return AttributeParser.getUnquoted(expression, quote, false, false);
174
return AttributeParser.getUnquoted(expression, quote, false, false,
161
178
public static class FMapper extends FunctionMapper {