init
This commit is contained in:
220
test/org/apache/jasper/compiler/Dumper.java
Normal file
220
test/org/apache/jasper/compiler/Dumper.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.apache.jasper.JasperException;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
class Dumper {
|
||||
|
||||
static class DumpVisitor extends Node.Visitor {
|
||||
private int indent = 0;
|
||||
|
||||
private String getAttributes(Attributes attrs) {
|
||||
if (attrs == null)
|
||||
return "";
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i=0; i < attrs.getLength(); i++) {
|
||||
buf.append(" " + attrs.getQName(i) + "=\""
|
||||
+ attrs.getValue(i) + "\"");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void printString(String str) {
|
||||
printIndent();
|
||||
System.out.print(str);
|
||||
}
|
||||
|
||||
private void printString(String prefix, String str, String suffix) {
|
||||
printIndent();
|
||||
if (str != null) {
|
||||
System.out.print(prefix + str + suffix);
|
||||
} else {
|
||||
System.out.print(prefix + suffix);
|
||||
}
|
||||
}
|
||||
|
||||
private void printAttributes(String prefix, Attributes attrs,
|
||||
String suffix) {
|
||||
printString(prefix, getAttributes(attrs), suffix);
|
||||
}
|
||||
|
||||
private void dumpBody(Node n) throws JasperException {
|
||||
Node.Nodes page = n.getBody();
|
||||
if (page != null) {
|
||||
// indent++;
|
||||
page.visit(this);
|
||||
// indent--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.PageDirective n) throws JasperException {
|
||||
printAttributes("<%@ page", n.getAttributes(), "%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.TaglibDirective n) throws JasperException {
|
||||
printAttributes("<%@ taglib", n.getAttributes(), "%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.IncludeDirective n) throws JasperException {
|
||||
printAttributes("<%@ include", n.getAttributes(), "%>");
|
||||
dumpBody(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.Comment n) throws JasperException {
|
||||
printString("<%--", n.getText(), "--%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.Declaration n) throws JasperException {
|
||||
printString("<%!", n.getText(), "%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.Expression n) throws JasperException {
|
||||
printString("<%=", n.getText(), "%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.Scriptlet n) throws JasperException {
|
||||
printString("<%", n.getText(), "%>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.IncludeAction n) throws JasperException {
|
||||
printAttributes("<jsp:include", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:include>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.ForwardAction n) throws JasperException {
|
||||
printAttributes("<jsp:forward", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:forward>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.GetProperty n) throws JasperException {
|
||||
printAttributes("<jsp:getProperty", n.getAttributes(), "/>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.SetProperty n) throws JasperException {
|
||||
printAttributes("<jsp:setProperty", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:setProperty>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.UseBean n) throws JasperException {
|
||||
printAttributes("<jsp:useBean", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:useBean>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.PlugIn n) throws JasperException {
|
||||
printAttributes("<jsp:plugin", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:plugin>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.ParamsAction n) throws JasperException {
|
||||
printAttributes("<jsp:params", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:params>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.ParamAction n) throws JasperException {
|
||||
printAttributes("<jsp:param", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:param>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.NamedAttribute n) throws JasperException {
|
||||
printAttributes("<jsp:attribute", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:attribute>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.JspBody n) throws JasperException {
|
||||
printAttributes("<jsp:body", n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</jsp:body>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.ELExpression n) throws JasperException {
|
||||
printString( "${" + n.getText() + "}" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.CustomTag n) throws JasperException {
|
||||
printAttributes("<" + n.getQName(), n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</" + n.getQName() + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.UninterpretedTag n) throws JasperException {
|
||||
String tag = n.getQName();
|
||||
printAttributes("<"+tag, n.getAttributes(), ">");
|
||||
dumpBody(n);
|
||||
printString("</" + tag + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Node.TemplateText n) throws JasperException {
|
||||
printString(n.getText());
|
||||
}
|
||||
|
||||
private void printIndent() {
|
||||
for (int i=0; i < indent; i++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void dump(Node n) {
|
||||
try {
|
||||
n.accept(new DumpVisitor());
|
||||
} catch (JasperException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void dump(Node.Nodes page) {
|
||||
try {
|
||||
page.visit(new DumpVisitor());
|
||||
} catch (JasperException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
179
test/org/apache/jasper/compiler/TestAttributeParser.java
Normal file
179
test/org/apache/jasper/compiler/TestAttributeParser.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.apache.el.TesterFunctions;
|
||||
import org.apache.jasper.el.ELContextImpl;
|
||||
|
||||
/**
|
||||
* Test the EL processing from JSP attributes. Similar tests may be found in
|
||||
* {@link org.apache.el.TestELEvaluation} and {@link org.apache.el.TestELInJsp}.
|
||||
*/
|
||||
public class TestAttributeParser {
|
||||
|
||||
/**
|
||||
* Test use of spaces in ternary expressions. This was primarily an EL
|
||||
* parser bug.
|
||||
*/
|
||||
@Test
|
||||
public void testBug42565() {
|
||||
Assert.assertEquals("false", evalAttr("${false?true:false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false?true: false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false?true :false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false?true : false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false? true:false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false? true: false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false? true :false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false? true : false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ?true:false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ?true: false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ?true :false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ?true : false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ? true:false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ? true: false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ? true :false}", '\"'));
|
||||
Assert.assertEquals("false", evalAttr("${false ? true : false}", '\"'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test use nested ternary expressions. Full tests in
|
||||
* {@link org.apache.el.TestELEvaluation}. This is just a smoke test to
|
||||
* ensure JSP attribute processing doesn't cause any additional issues.
|
||||
*/
|
||||
@Test
|
||||
public void testBug44994() {
|
||||
Assert.assertEquals("none",
|
||||
evalAttr("${0 lt 0 ? 1 lt 0 ? 'many': 'one': 'none'}", '\"'));
|
||||
Assert.assertEquals("one",
|
||||
evalAttr("${0 lt 1 ? 1 lt 1 ? 'many': 'one': 'none'}", '\"'));
|
||||
Assert.assertEquals("many",
|
||||
evalAttr("${0 lt 2 ? 1 lt 2 ? 'many': 'one': 'none'}", '\"'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the quoting requirements of JSP attributes. This doesn't make use of
|
||||
* EL. See {@link #testBug45451()} for a test that combines JSP attribute
|
||||
* quoting and EL quoting.
|
||||
*/
|
||||
@Test
|
||||
public void testBug45015() {
|
||||
// Warning: Java String quoting vs. JSP attribute quoting
|
||||
Assert.assertEquals("hello 'world'", evalAttr("hello 'world'", '\"'));
|
||||
Assert.assertEquals("hello 'world", evalAttr("hello 'world", '\"'));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world'", '\"'));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world\\'", '\"'));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\\\"", '\"'));
|
||||
Assert.assertEquals("hello \"world\"", evalAttr("hello \"world\"", '\"'));
|
||||
Assert.assertEquals("hello \"world", evalAttr("hello \"world", '\"'));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\"", '\"'));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world\\'", '\"'));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\\\"", '\"'));
|
||||
|
||||
Assert.assertEquals("hello 'world'", evalAttr("hello 'world'", '\''));
|
||||
Assert.assertEquals("hello 'world", evalAttr("hello 'world", '\''));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world'", '\''));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world\\'", '\''));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\\\"", '\''));
|
||||
Assert.assertEquals("hello \"world\"", evalAttr("hello \"world\"", '\''));
|
||||
Assert.assertEquals("hello \"world", evalAttr("hello \"world", '\''));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\"", '\''));
|
||||
Assert.assertEquals("hello world'", evalAttr("hello world\\'", '\''));
|
||||
Assert.assertEquals("hello world\"", evalAttr("hello world\\\"", '\''));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug45451() {
|
||||
Assert.assertEquals("2", evalAttr("${1+1}", '\"'));
|
||||
Assert.assertEquals("${1+1}", evalAttr("\\${1+1}", '\"'));
|
||||
Assert.assertEquals("\\2", evalAttr("\\\\${1+1}", '\"'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49081() {
|
||||
Assert.assertEquals("#2", evalAttr("#${1+1}", '\"'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteral() {
|
||||
// Inspired by work on bug 45451, comments from kkolinko on the dev
|
||||
// list and looking at the spec to find some edge cases
|
||||
|
||||
// '\' is only an escape character inside a StringLiteral
|
||||
// Attribute escaping does not apply inside EL expressions
|
||||
Assert.assertEquals("\\", evalAttr("${'\\\\'}", '\"'));
|
||||
|
||||
// Can use ''' inside '"' when quoting with '"' and vice versa without
|
||||
// escaping
|
||||
Assert.assertEquals("\\\"", evalAttr("${'\\\\\"'}", '\"'));
|
||||
Assert.assertEquals("\"\\", evalAttr("${'\\\"\\\\'}", '\"'));
|
||||
Assert.assertEquals("\\'", evalAttr("${'\\\\\\''}", '\"'));
|
||||
Assert.assertEquals("'\\", evalAttr("${'\\'\\\\'}", '\"'));
|
||||
|
||||
// Quoting <% and %>
|
||||
Assert.assertEquals("hello <% world", evalAttr("hello <\\% world", '\"'));
|
||||
Assert.assertEquals("hello %> world", evalAttr("hello %> world", '\"'));
|
||||
|
||||
// Test that the end of literal in EL expression is recognized in
|
||||
// parseEL(), be it quoted with single or double quotes. That is, that
|
||||
// AttributeParser correctly switches between parseLiteral and parseEL
|
||||
// methods.
|
||||
//
|
||||
// The test is based on the difference in how the '\' character is printed:
|
||||
// when in parseLiteral \\${ will be printed as ${'\'}${, but if we are still
|
||||
// inside of parseEL it will be printed as \${, thus preventing the EL
|
||||
// expression that follows from being evaluated.
|
||||
//
|
||||
Assert.assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\'bar\'}\\\\${\'baz\'}", '\"'));
|
||||
Assert.assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\"bar\"}\\\\${\'baz\'}", '\"'));
|
||||
Assert.assertEquals("foo\\bar\\baz", evalAttr("${\"foo\"}\\\\${\'bar\'}\\\\${\"baz\"}", '\"'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptExpressionLiterals() {
|
||||
Assert.assertEquals(" \"hello world\" ", parseScriptExpression(
|
||||
" \"hello world\" ", (char) 0));
|
||||
Assert.assertEquals(" \"hello \\\"world\" ", parseScriptExpression(
|
||||
" \"hello \\\\\"world\" ", (char) 0));
|
||||
}
|
||||
|
||||
private String evalAttr(String expression, char quote) {
|
||||
|
||||
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
|
||||
ELContextImpl ctx = new ELContextImpl(exprFactory);
|
||||
ctx.setFunctionMapper(new TesterFunctions.FMapper());
|
||||
ValueExpression ve = exprFactory.createValueExpression(ctx,
|
||||
AttributeParser.getUnquoted(expression, quote, false, false,
|
||||
false, false),
|
||||
String.class);
|
||||
return (String) ve.getValue(ctx);
|
||||
}
|
||||
|
||||
private String parseScriptExpression(String expression, char quote) {
|
||||
return AttributeParser.getUnquoted(expression, quote, false, false,
|
||||
false, false);
|
||||
}
|
||||
}
|
||||
208
test/org/apache/jasper/compiler/TestCompiler.java
Normal file
208
test/org/apache/jasper/compiler/TestCompiler.java
Normal file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestCompiler extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug49726a() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
Map<String,List<String>> headers = new HashMap<>();
|
||||
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug49nnn/bug49726a.jsp",
|
||||
res, headers);
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
|
||||
// Check content type
|
||||
String contentType = getSingleHeader("Content-Type", headers);
|
||||
Assert.assertTrue(contentType.startsWith("text/html"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49726b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
Map<String,List<String>> headers = new HashMap<>();
|
||||
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug49nnn/bug49726b.jsp",
|
||||
res, headers);
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
|
||||
// Check content type
|
||||
String contentType = getSingleHeader("Content-Type", headers);
|
||||
Assert.assertTrue(contentType.startsWith("text/plain"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257a() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
// foo;bar.jsp
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%3bbar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo&bar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257c() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
// foo#bar.jsp
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%23bar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257d() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
// foo%bar.jsp
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%25bar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257e() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo+bar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257f() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%20bar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257g() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%20bar/foobar.jsp");
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
assertEcho(result, "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug53257z() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
// Check that URL decoding is not done twice
|
||||
ByteChunk res = new ByteChunk();
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug53257/foo%2525bar.jsp", res, null);
|
||||
Assert.assertEquals(404, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug51584() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-fragments");
|
||||
Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
skipTldsForResourceJars(ctx);
|
||||
|
||||
tomcat.start();
|
||||
|
||||
// No further tests required. The bug triggers an infinite loop on
|
||||
// context start so the test will crash before it reaches this point if
|
||||
// it fails
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug55262() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug55262.jsp");
|
||||
String result = res.toString();
|
||||
Pattern prelude = Pattern.compile(
|
||||
"(.*This is a prelude\\.){2}.*",
|
||||
Pattern.MULTILINE | Pattern.DOTALL);
|
||||
Pattern coda = Pattern.compile(
|
||||
"(.*This is a coda\\.){2}.*",
|
||||
Pattern.MULTILINE|Pattern.DOTALL);
|
||||
Assert.assertTrue(prelude.matcher(result).matches());
|
||||
Assert.assertTrue(coda.matcher(result).matches());
|
||||
}
|
||||
|
||||
/** Assertion for text printed by tags:echo */
|
||||
private static void assertEcho(String result, String expected) {
|
||||
Assert.assertTrue(result, result.indexOf("<p>" + expected + "</p>") > 0);
|
||||
}
|
||||
}
|
||||
102
test/org/apache/jasper/compiler/TestELInterpreterFactory.java
Normal file
102
test/org/apache/jasper/compiler/TestELInterpreterFactory.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.jasper.JspCompilationContext;
|
||||
import org.apache.jasper.compiler.ELInterpreterFactory.DefaultELInterpreter;
|
||||
|
||||
public class TestELInterpreterFactory extends TomcatBaseTest {
|
||||
|
||||
public static class SimpleELInterpreter implements ELInterpreter {
|
||||
|
||||
@Override
|
||||
public String interpreterCall(JspCompilationContext context,
|
||||
boolean isTagFile, String expression, Class<?> expectedType,
|
||||
String fnmapvar) {
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug54239() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp");
|
||||
Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
tomcat.start();
|
||||
|
||||
ServletContext context = ctx.getServletContext();
|
||||
|
||||
ELInterpreter interpreter =
|
||||
ELInterpreterFactory.getELInterpreter(context);
|
||||
Assert.assertNotNull(interpreter);
|
||||
Assert.assertTrue(interpreter instanceof DefaultELInterpreter);
|
||||
|
||||
context.removeAttribute(ELInterpreter.class.getName());
|
||||
|
||||
context.setAttribute(ELInterpreter.class.getName(),
|
||||
SimpleELInterpreter.class.getName());
|
||||
interpreter = ELInterpreterFactory.getELInterpreter(context);
|
||||
Assert.assertNotNull(interpreter);
|
||||
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
|
||||
|
||||
context.removeAttribute(ELInterpreter.class.getName());
|
||||
|
||||
SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter();
|
||||
context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter);
|
||||
interpreter = ELInterpreterFactory.getELInterpreter(context);
|
||||
Assert.assertNotNull(interpreter);
|
||||
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
|
||||
Assert.assertTrue(interpreter == simpleInterpreter);
|
||||
|
||||
context.removeAttribute(ELInterpreter.class.getName());
|
||||
|
||||
ctx.stop();
|
||||
ctx.addApplicationListener(Bug54239Listener.class.getName());
|
||||
ctx.start();
|
||||
|
||||
interpreter = ELInterpreterFactory.getELInterpreter(ctx.getServletContext());
|
||||
Assert.assertNotNull(interpreter);
|
||||
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
|
||||
}
|
||||
|
||||
public static class Bug54239Listener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
sce.getServletContext().setInitParameter(ELInterpreter.class.getName(),
|
||||
SimpleELInterpreter.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
}
|
||||
324
test/org/apache/jasper/compiler/TestELParser.java
Normal file
324
test/org/apache/jasper/compiler/TestELParser.java
Normal file
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.jasper.JasperException;
|
||||
import org.apache.jasper.compiler.ELNode.Nodes;
|
||||
import org.apache.jasper.compiler.ELParser.TextBuilder;
|
||||
|
||||
/**
|
||||
* You will need to keep your wits about you when working with this class. Keep
|
||||
* in mind the following:
|
||||
* <ul>
|
||||
* <li>If in doubt, read the EL and JSP specifications. Twice.</li>
|
||||
* <li>The escaping rules are complex and subtle. The explanation below (as well
|
||||
* as the tests and the implementation) may have missed an edge case despite
|
||||
* trying hard not to.
|
||||
* <li>The strings passed to {@link #doTestParser(String,String)} are Java
|
||||
* escaped in the source code and will be unescaped before being used.</li>
|
||||
* <li>LiteralExpressions always occur outside of "${...}" and "#{...}". Literal
|
||||
* expressions escape '$' and '#' with '\\'</li>
|
||||
* <li>LiteralStrings always occur inside "${...}" or "#{...}". Literal strings
|
||||
* escape '\'', '\"' and '\\' with '\\'. Escaping '\"' is optional if the
|
||||
* literal string is delimited by '\''. Escaping '\'' is optional if the
|
||||
* literal string is delimited by '\"'.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class TestELParser {
|
||||
|
||||
@Test
|
||||
public void testText() throws JasperException {
|
||||
doTestParser("foo", "foo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLiteral() throws JasperException {
|
||||
doTestParser("${'foo'}", "foo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVariable() throws JasperException {
|
||||
doTestParser("${test}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunction01() throws JasperException {
|
||||
doTestParser("${do(x)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunction02() throws JasperException {
|
||||
doTestParser("${do:it(x)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunction03() throws JasperException {
|
||||
doTestParser("${do:it(x,y)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunction04() throws JasperException {
|
||||
doTestParser("${do:it(x,y,z)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunction05() throws JasperException {
|
||||
doTestParser("${do:it(x, '\\\\y',z)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompound01() throws JasperException {
|
||||
doTestParser("1${'foo'}1", "1foo1");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompound02() throws JasperException {
|
||||
doTestParser("1${test}1", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompound03() throws JasperException {
|
||||
doTestParser("${foo}${bar}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary01() throws JasperException {
|
||||
doTestParser("${true?true:false}", "true");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary02() throws JasperException {
|
||||
doTestParser("${a==1?true:false}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary03() throws JasperException {
|
||||
doTestParser("${a eq1?true:false}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary04() throws JasperException {
|
||||
doTestParser(" ${ a eq 1 ? true : false } ", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary05() throws JasperException {
|
||||
// Note this is invalid EL
|
||||
doTestParser("${aeq1?true:false}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary06() throws JasperException {
|
||||
doTestParser("${do:it(a eq1?true:false,y)}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary07() throws JasperException {
|
||||
doTestParser(" ${ do:it( a eq 1 ? true : false, y ) } ", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary08() throws JasperException {
|
||||
doTestParser(" ${ do:it ( a eq 1 ? true : false, y ) } ", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary09() throws JasperException {
|
||||
doTestParser(" ${ do : it ( a eq 1 ? true : false, y ) } ", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary10() throws JasperException {
|
||||
doTestParser(" ${!empty my:link(foo)} ", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary11() throws JasperException {
|
||||
doTestParser("${true?'true':'false'}", "true");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary12() throws JasperException {
|
||||
doTestParser("${true?'tr\"ue':'false'}", "tr\"ue");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary13() throws JasperException {
|
||||
doTestParser("${true?'tr\\'ue':'false'}", "tr'ue");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernaryBug56031() throws JasperException {
|
||||
doTestParser("${my:link(!empty registration ? registration : '/test/registration')}", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testQuotes01() throws JasperException {
|
||||
doTestParser("'", "'");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testQuotes02() throws JasperException {
|
||||
doTestParser("'${foo}'", null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testQuotes03() throws JasperException {
|
||||
doTestParser("'${'foo'}'", "'foo'");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape01() throws JasperException {
|
||||
doTestParser("${'\\\\'}", "\\");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape02() throws JasperException {
|
||||
doTestParser("\\\\x${'\\\\'}", "\\\\x\\");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape03() throws JasperException {
|
||||
doTestParser("\\\\", "\\\\");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape04() throws JasperException {
|
||||
// When parsed as EL in JSP the escaping of $ as \$ is optional
|
||||
doTestParser("\\$", "\\$", "$");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape05() throws JasperException {
|
||||
// When parsed as EL in JSP the escaping of # as \# is optional
|
||||
doTestParser("\\#", "\\#", "#");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape07() throws JasperException {
|
||||
doTestParser("${'\\\\$'}", "\\$");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape08() throws JasperException {
|
||||
doTestParser("${'\\\\#'}", "\\#");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape09() throws JasperException {
|
||||
doTestParser("\\${", "${");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape10() throws JasperException {
|
||||
doTestParser("\\#{", "#{");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscape11() throws JasperException {
|
||||
// Bug 56612
|
||||
doTestParser("${'\\'\\''}", "''");
|
||||
}
|
||||
|
||||
|
||||
private void doTestParser(String input, String expected) throws JasperException {
|
||||
doTestParser(input, expected, input);
|
||||
}
|
||||
|
||||
private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
|
||||
|
||||
ELException elException = null;
|
||||
String elResult = null;
|
||||
|
||||
// Don't try and evaluate expressions that depend on variables or functions
|
||||
if (expectedResult != null) {
|
||||
try {
|
||||
ELManager manager = new ELManager();
|
||||
ELContext context = manager.getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
ValueExpression ve = factory.createValueExpression(context, input, String.class);
|
||||
elResult = ve.getValue(context).toString();
|
||||
Assert.assertEquals(expectedResult, elResult);
|
||||
} catch (ELException ele) {
|
||||
elException = ele;
|
||||
}
|
||||
}
|
||||
|
||||
Nodes nodes = null;
|
||||
try {
|
||||
nodes = ELParser.parse(input, false);
|
||||
Assert.assertNull(elException);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
Assert.assertNotNull(elResult, elException);
|
||||
// Not strictly true but enables us to report both
|
||||
iae.initCause(elException);
|
||||
throw iae;
|
||||
}
|
||||
|
||||
TextBuilder textBuilder = new TextBuilder(false);
|
||||
|
||||
nodes.visit(textBuilder);
|
||||
|
||||
Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
|
||||
}
|
||||
}
|
||||
95
test/org/apache/jasper/compiler/TestEncodingDetector.java
Normal file
95
test/org/apache/jasper/compiler/TestEncodingDetector.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestEncodingDetector extends TomcatBaseTest {
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> inputs() {
|
||||
/// Note: These files are saved using the encoding indicated by the BOM
|
||||
List<Object[]> result = new ArrayList<>();
|
||||
result.add(new Object[] { "bom-none-prolog-none.jsp", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-none-prolog-none.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-none-prolog-utf16be.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-none-prolog-utf16le.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-none-prolog-utf8.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf8-prolog-none.jsp", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf8-prolog-none.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf8-prolog-utf16be.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bom-utf8-prolog-utf16le.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bom-utf8-prolog-utf8.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16be-prolog-none.jsp", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16be-prolog-none.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16be-prolog-utf16be.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16be-prolog-utf16le.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bom-utf16be-prolog-utf8.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bom-utf16le-prolog-none.jsp", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16le-prolog-none.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16le-prolog-utf16be.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bom-utf16le-prolog-utf16le.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
result.add(new Object[] { "bom-utf16le-prolog-utf8.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bug60769a.jspx", Integer.valueOf(500), null });
|
||||
result.add(new Object[] { "bug60769b.jspx", Integer.valueOf(200), Boolean.TRUE });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Parameter(0)
|
||||
public String jspName;
|
||||
|
||||
@Parameter(1)
|
||||
public int expectedResponseCode;
|
||||
|
||||
@Parameter(2)
|
||||
public Boolean responseBodyOK;
|
||||
|
||||
@Test
|
||||
public void testEncodedJsp() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk responseBody = new ByteChunk();
|
||||
int rc = getUrl("http://localhost:" + getPort() + "/test/jsp/encoding/" + jspName,
|
||||
responseBody, null);
|
||||
|
||||
Assert.assertEquals(expectedResponseCode, rc);
|
||||
|
||||
if (expectedResponseCode == 200) {
|
||||
// trim() to remove whitespace like new lines
|
||||
String bodyText = responseBody.toString().trim();
|
||||
if (responseBodyOK.booleanValue()) {
|
||||
Assert.assertEquals("OK", bodyText);
|
||||
} else {
|
||||
Assert.assertNotEquals("OK", bodyText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
275
test/org/apache/jasper/compiler/TestGenerator.java
Normal file
275
test/org/apache/jasper/compiler/TestGenerator.java
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.TagData;
|
||||
import javax.servlet.jsp.tagext.TagExtraInfo;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
import javax.servlet.jsp.tagext.VariableInfo;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestGenerator extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug45015a() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug45nnn/bug45015a.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
// Beware of the differences between escaping in JSP attributes and
|
||||
// in Java Strings
|
||||
assertEcho(result, "00-hello 'world'");
|
||||
assertEcho(result, "01-hello 'world");
|
||||
assertEcho(result, "02-hello world'");
|
||||
assertEcho(result, "03-hello world'");
|
||||
assertEcho(result, "04-hello world\"");
|
||||
assertEcho(result, "05-hello \"world\"");
|
||||
assertEcho(result, "06-hello \"world");
|
||||
assertEcho(result, "07-hello world\"");
|
||||
assertEcho(result, "08-hello world'");
|
||||
assertEcho(result, "09-hello world\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug45015b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug45nnn/bug45015b.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug45015c() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug45nnn/bug45015c.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48701Fail() throws Exception {
|
||||
getTomcatInstanceTestWebapp(true, true);
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48701-fail.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48701UseBean() throws Exception {
|
||||
testBug48701("bug48nnn/bug48701-UseBean.jsp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48701VariableInfo() throws Exception {
|
||||
testBug48701("bug48nnn/bug48701-VI.jsp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48701TagVariableInfoNameGiven() throws Exception {
|
||||
testBug48701("bug48nnn/bug48701-TVI-NG.jsp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48701TagVariableInfoNameFromAttribute() throws Exception {
|
||||
testBug48701("bug48nnn/bug48701-TVI-NFA.jsp");
|
||||
}
|
||||
|
||||
private void testBug48701(String jsp) throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/" + jsp);
|
||||
|
||||
String result = res.toString();
|
||||
assertEcho(result, "00-PASS");
|
||||
}
|
||||
|
||||
public static class Bug48701 extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String beanName = null;
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doStartTag() throws JspException {
|
||||
Bean bean = new Bean();
|
||||
bean.setTime((new Date()).toString());
|
||||
pageContext.setAttribute("now", bean);
|
||||
return super.doStartTag();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class Bug48701TEI extends TagExtraInfo {
|
||||
|
||||
@Override
|
||||
public VariableInfo[] getVariableInfo(TagData data) {
|
||||
return new VariableInfo[] {
|
||||
new VariableInfo("now", Bean.class.getCanonicalName(),
|
||||
true, VariableInfo.AT_END)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Bean {
|
||||
private String time;
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49799() throws Exception {
|
||||
|
||||
String[] expected = { "<p style=\"color:red\">00-Red</p>",
|
||||
"<p>01-Not Red</p>",
|
||||
"<p style=\"color:red\">02-Red</p>",
|
||||
"<p>03-Not Red</p>",
|
||||
"<p style=\"color:red\">04-Red</p>",
|
||||
"<p>05-Not Red</p>"};
|
||||
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug49nnn/bug49799.jsp", res, null);
|
||||
|
||||
// Check request completed
|
||||
String result = res.toString();
|
||||
String[] lines = result.split("\n|\r|\r\n");
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
if (line.length() > 0) {
|
||||
Assert.assertEquals(expected[i], line);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Assertion for text printed by tags:echo */
|
||||
private static void assertEcho(String result, String expected) {
|
||||
Assert.assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug56529() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk bc = new ByteChunk();
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug56529.jsp", bc, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
String response = bc.toStringInternal();
|
||||
Assert.assertTrue(response,
|
||||
response.contains("[1:attribute1: '', attribute2: '']"));
|
||||
Assert.assertTrue(response,
|
||||
response.contains("[2:attribute1: '', attribute2: '']"));
|
||||
}
|
||||
|
||||
public static class Bug56529 extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String attribute1 = null;
|
||||
|
||||
private String attribute2 = null;
|
||||
|
||||
public void setAttribute1(String attribute1) {
|
||||
this.attribute1 = attribute1;
|
||||
}
|
||||
|
||||
public String getAttribute1() {
|
||||
return attribute1;
|
||||
}
|
||||
|
||||
public void setAttribute2(String attribute2) {
|
||||
this.attribute2 = attribute2;
|
||||
}
|
||||
|
||||
public String getAttribute2() {
|
||||
return attribute2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doEndTag() throws JspException {
|
||||
try {
|
||||
pageContext.getOut().print(
|
||||
"attribute1: '" + attribute1 + "', " + "attribute2: '"
|
||||
+ attribute2 + "'");
|
||||
} catch (IOException e) {
|
||||
throw new JspException(e);
|
||||
}
|
||||
return EVAL_PAGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug56581() throws LifecycleException {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
try {
|
||||
getUrl("http://localhost:" + getPort()
|
||||
+ "/test/bug5nnnn/bug56581.jsp", res, null);
|
||||
Assert.fail("An IOException was expected.");
|
||||
} catch (IOException expected) {
|
||||
// ErrorReportValve in Tomcat 8.0.9+ flushes and aborts the
|
||||
// connection when an unexpected error is encountered and response
|
||||
// has already been committed. It results in an exception here:
|
||||
// java.io.IOException: Premature EOF
|
||||
}
|
||||
|
||||
String result = res.toString();
|
||||
Assert.assertTrue(result.startsWith("0 Hello world!\n"));
|
||||
Assert.assertTrue(result.endsWith("999 Hello world!\n"));
|
||||
}
|
||||
}
|
||||
143
test/org/apache/jasper/compiler/TestJspConfig.java
Normal file
143
test/org/apache/jasper/compiler/TestJspConfig.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestJspConfig extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testServlet22NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-2.2");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-${'hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServlet23NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-2.3");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-${'hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServlet24NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-2.4");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServlet25NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-2.5");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServlet30NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-3.0");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServlet31NoEL() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir = new File("test/webapp-3.1");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/el-as-literal.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
}
|
||||
123
test/org/apache/jasper/compiler/TestJspDocumentParser.java
Normal file
123
test/org/apache/jasper/compiler/TestJspDocumentParser.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
public class TestJspDocumentParser extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug47977() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug47977.jspx", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48827() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug48nnn/bug48827.jspx");
|
||||
} catch (IOException ioe) {
|
||||
e = ioe;
|
||||
}
|
||||
|
||||
// Should not fail
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug54801() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk bc = new ByteChunk();
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug54801a.jspx", bc, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
|
||||
bc.recycle();
|
||||
rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug54801b.jspx", bc, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug54821() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk bc = new ByteChunk();
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug54821a.jspx", bc, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
|
||||
bc.recycle();
|
||||
rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug54821b.jspx", bc, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaValidation() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
String path = "http://localhost:" + getPort() + "/test/valid.jspx";
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setValidating(true);
|
||||
dbf.setFeature("http://apache.org/xml/features/validation/schema", true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(new ErrorHandler() {
|
||||
@Override
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatalError(SAXParseException exception) throws SAXException {
|
||||
throw exception;
|
||||
}
|
||||
});
|
||||
Document document = db.parse(path);
|
||||
Assert.assertEquals("urn:valid", document.getDocumentElement().getNamespaceURI());
|
||||
Assert.assertEquals("root", document.getDocumentElement().getLocalName());
|
||||
}
|
||||
}
|
||||
35
test/org/apache/jasper/compiler/TestJspReader.java
Normal file
35
test/org/apache/jasper/compiler/TestJspReader.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestJspReader extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug53986() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug53986.jsp");
|
||||
Assert.assertTrue(res.toString().contains("OK"));
|
||||
}
|
||||
}
|
||||
73
test/org/apache/jasper/compiler/TestNode.java
Normal file
73
test/org/apache/jasper/compiler/TestNode.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.jasper.compiler.Node.PageDirective;
|
||||
|
||||
public class TestNode {
|
||||
|
||||
/*
|
||||
* https://bz.apache.org/bugzilla/show_bug.cgi?id=57099
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testPageDirectiveImport01() {
|
||||
doTestPageDirectiveImport("java.io.*;\r\n\timport java.net.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageDirectiveImport02() {
|
||||
doTestPageDirectiveImport("a,b,c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageDirectiveImport03() {
|
||||
doTestPageDirectiveImport(" a , b , c ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageDirectiveImport04() {
|
||||
doTestPageDirectiveImport(" a\n , \r\nb , \nc\r ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageDirectiveImport05() {
|
||||
doTestPageDirectiveImport("java.util.List,java.util.ArrayList,java.util.Set");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testPageDirectiveImport06() {
|
||||
doTestPageDirectiveImport("java.util.List;import java.util.ArrayList; import java.util.Set");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageDirectiveImport07() {
|
||||
doTestPageDirectiveImport("java .\nutil.List,java.util.ArrayList,java.util.Set");
|
||||
}
|
||||
|
||||
private void doTestPageDirectiveImport(String importDirective) {
|
||||
PageDirective pd = new PageDirective(null, null, null);
|
||||
pd.addImport(importDirective);
|
||||
List<String> imports = pd.getImports();
|
||||
|
||||
Assert.assertEquals(3, imports.size());
|
||||
}
|
||||
}
|
||||
39
test/org/apache/jasper/compiler/TestNodeIntegration.java
Normal file
39
test/org/apache/jasper/compiler/TestNodeIntegration.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestNodeIntegration extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testJspAttributeIsLiteral() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug55642a.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(
|
||||
result.indexOf("/test/bug5nnnn/bug55642b.jsp?foo=bar&a=1&b=2") > 0);
|
||||
}
|
||||
}
|
||||
291
test/org/apache/jasper/compiler/TestParser.java
Normal file
291
test/org/apache/jasper/compiler/TestParser.java
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
/**
|
||||
* Tests are duplicated in {@link TestParserNoStrictWhitespace} with the strict
|
||||
* whitespace parsing disabled.
|
||||
*/
|
||||
public class TestParser extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug48627() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48627.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
// Beware of the differences between escaping in JSP attributes and
|
||||
// in Java Strings
|
||||
assertEcho(result, "00-\\");
|
||||
assertEcho(result, "01-\\");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48668a() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48668a.jsp");
|
||||
String result = res.toString();
|
||||
assertEcho(result, "00-Hello world</p>#{foo.bar}");
|
||||
assertEcho(result, "01-Hello world</p>${foo.bar}");
|
||||
assertEcho(result, "10-Hello ${'foo.bar}");
|
||||
assertEcho(result, "11-Hello ${'foo.bar}");
|
||||
assertEcho(result, "12-Hello #{'foo.bar}");
|
||||
assertEcho(result, "13-Hello #{'foo.bar}");
|
||||
assertEcho(result, "14-Hello ${'foo}");
|
||||
assertEcho(result, "15-Hello ${'foo}");
|
||||
assertEcho(result, "16-Hello #{'foo}");
|
||||
assertEcho(result, "17-Hello #{'foo}");
|
||||
assertEcho(result, "18-Hello ${'foo.bar}");
|
||||
assertEcho(result, "19-Hello ${'foo.bar}");
|
||||
assertEcho(result, "20-Hello #{'foo.bar}");
|
||||
assertEcho(result, "21-Hello #{'foo.bar}");
|
||||
assertEcho(result, "30-Hello ${'foo}");
|
||||
assertEcho(result, "31-Hello ${'foo}");
|
||||
assertEcho(result, "32-Hello #{'foo}");
|
||||
assertEcho(result, "33-Hello #{'foo}");
|
||||
assertEcho(result, "34-Hello ${'foo}");
|
||||
assertEcho(result, "35-Hello ${'foo}");
|
||||
assertEcho(result, "36-Hello #{'foo}");
|
||||
assertEcho(result, "37-Hello #{'foo}");
|
||||
assertEcho(result, "40-Hello ${'foo}");
|
||||
assertEcho(result, "41-Hello ${'foo}");
|
||||
assertEcho(result, "42-Hello #{'foo}");
|
||||
assertEcho(result, "43-Hello #{'foo}");
|
||||
assertEcho(result, "50-Hello ${'foo}");
|
||||
assertEcho(result, "51-Hello ${'foo}");
|
||||
assertEcho(result, "52-Hello #{'foo}");
|
||||
assertEcho(result, "53-Hello #{'foo}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48668b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48668b.jsp");
|
||||
String result = res.toString();
|
||||
assertEcho(result, "00-Hello world</p>#{foo.bar}");
|
||||
assertEcho(result, "01-Hello world</p>#{foo2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297NoSpaceStrict() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297NoSpace.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297DuplicateAttr() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297DuplicateAttr.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultipleImport1() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultipleImport1.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(200, sc);
|
||||
assertEcho(res.toString(), "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultipleImport2() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultipleImport2.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(200, sc);
|
||||
assertEcho(res.toString(), "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultiplePageEncoding1() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultiplePageEncoding1.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultiplePageEncoding2() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultiplePageEncoding2.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultiplePageEncoding3() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultiplePageEncoding3.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297MultiplePageEncoding4() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297MultiplePageEncoding4.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297Tag() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297Tag.jsp", res, null);
|
||||
|
||||
Assert.assertEquals(200, sc);
|
||||
assertEcho(res.toString(), "OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug52335() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug52335.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
// Beware of the differences between escaping in JSP attributes and
|
||||
// in Java Strings
|
||||
assertEcho(result, "00 - \\% \\\\% <%");
|
||||
assertEcho(result, "01 - <b><%</b>");
|
||||
assertEcho(result, "02 - <p>Foo</p><%");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug55198() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug55198.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result,
|
||||
result.contains(""1foo1<&>"")
|
||||
|| result.contains(""1foo1<&>""));
|
||||
Assert.assertTrue(result,
|
||||
result.contains(""2bar2<&>"")
|
||||
|| result.contains(""2bar2<&>""));
|
||||
Assert.assertTrue(result,
|
||||
result.contains(""3a&b3"")
|
||||
|| result.contains(""3a&b3""));
|
||||
Assert.assertTrue(result,
|
||||
result.contains(""4&4"")
|
||||
|| result.contains(""4&4""));
|
||||
Assert.assertTrue(result,
|
||||
result.contains(""5'5"")
|
||||
|| result.contains(""5'5""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug56265() throws Exception {
|
||||
getTomcatInstanceTestWebapp(true, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug56265.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result,
|
||||
result.contains("[1: [data-test]: [window.alert('Hello World <&>!')]]"));
|
||||
Assert.assertTrue(result,
|
||||
result.contains("[2: [data-test]: [window.alert('Hello World <&>!')]]"));
|
||||
Assert.assertTrue(result,
|
||||
result.contains("[3: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
|
||||
Assert.assertTrue(result,
|
||||
result.contains("[4: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug56334And56561() throws Exception {
|
||||
getTomcatInstanceTestWebapp(true, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug5nnnn/bug56334and56561.jspx");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
// NOTE: The expected values must themselves be \ escaped below
|
||||
Assert.assertTrue(result, result.contains("01a\\?resize01a"));
|
||||
Assert.assertTrue(result, result.contains("01b\\\\x\\?resize01b"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"02a\\\\?resize02a\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"02b\\\\\\\\x\\\\?resize02b\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"03a\\?resize03a\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"03b\\\\x\\?resize03b\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<04a\\?resize04a/>"));
|
||||
Assert.assertTrue(result, result.contains("<04b\\\\x\\?resize04b/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"05a$${&\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"05b$${&2\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set data-value=\"05c##{>hello<\"/>"));
|
||||
Assert.assertTrue(result, result.contains("05x:<set data-value=\"\"/>"));
|
||||
Assert.assertTrue(result, result.contains("<set xmlns:foo=\"urn:06a\\bar\\baz\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07a:<set data-value=\"\\?resize\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07b:<set data-content=\"\\?resize=.+\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07c:<set data-content=\"\\?resize=.+\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07d:<set data-content=\"false\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07e:<set data-content=\"false\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07f:<set data-content=\"\\\'something\'\"/>"));
|
||||
Assert.assertTrue(result, result.contains("07g:<set data-content=\"\\\'something\'\"/>"));
|
||||
}
|
||||
|
||||
/** Assertion for text printed by tags:echo */
|
||||
private static void assertEcho(String result, String expected) {
|
||||
Assert.assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
/**
|
||||
* Tests are duplicated in {@link TestParser} with the strict whitespace parsing
|
||||
* enabled by default.
|
||||
*/
|
||||
public class TestParserNoStrictWhitespace extends TomcatBaseTest {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty(
|
||||
"org.apache.jasper.compiler.Parser.STRICT_WHITESPACE",
|
||||
"false");
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48627() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48627.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
// Beware of the differences between escaping in JSP attributes and
|
||||
// in Java Strings
|
||||
assertEcho(result, "00-\\");
|
||||
assertEcho(result, "01-\\");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48668a() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48668a.jsp");
|
||||
String result = res.toString();
|
||||
assertEcho(result, "00-Hello world</p>#{foo.bar}");
|
||||
assertEcho(result, "01-Hello world</p>${foo.bar}");
|
||||
assertEcho(result, "10-Hello ${'foo.bar}");
|
||||
assertEcho(result, "11-Hello ${'foo.bar}");
|
||||
assertEcho(result, "12-Hello #{'foo.bar}");
|
||||
assertEcho(result, "13-Hello #{'foo.bar}");
|
||||
assertEcho(result, "14-Hello ${'foo}");
|
||||
assertEcho(result, "15-Hello ${'foo}");
|
||||
assertEcho(result, "16-Hello #{'foo}");
|
||||
assertEcho(result, "17-Hello #{'foo}");
|
||||
assertEcho(result, "18-Hello ${'foo.bar}");
|
||||
assertEcho(result, "19-Hello ${'foo.bar}");
|
||||
assertEcho(result, "20-Hello #{'foo.bar}");
|
||||
assertEcho(result, "21-Hello #{'foo.bar}");
|
||||
assertEcho(result, "30-Hello ${'foo}");
|
||||
assertEcho(result, "31-Hello ${'foo}");
|
||||
assertEcho(result, "32-Hello #{'foo}");
|
||||
assertEcho(result, "33-Hello #{'foo}");
|
||||
assertEcho(result, "34-Hello ${'foo}");
|
||||
assertEcho(result, "35-Hello ${'foo}");
|
||||
assertEcho(result, "36-Hello #{'foo}");
|
||||
assertEcho(result, "37-Hello #{'foo}");
|
||||
assertEcho(result, "40-Hello ${'foo}");
|
||||
assertEcho(result, "41-Hello ${'foo}");
|
||||
assertEcho(result, "42-Hello #{'foo}");
|
||||
assertEcho(result, "43-Hello #{'foo}");
|
||||
assertEcho(result, "50-Hello ${'foo}");
|
||||
assertEcho(result, "51-Hello ${'foo}");
|
||||
assertEcho(result, "52-Hello #{'foo}");
|
||||
assertEcho(result, "53-Hello #{'foo}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48668b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug48nnn/bug48668b.jsp");
|
||||
String result = res.toString();
|
||||
assertEcho(result, "00-Hello world</p>#{foo.bar}");
|
||||
assertEcho(result, "01-Hello world</p>#{foo2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297NoSpaceNotStrict() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297NoSpace.jsp", res, null);
|
||||
|
||||
|
||||
Assert.assertEquals(200, sc);
|
||||
assertEcho(res.toString(), "Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49297DuplicateAttr() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int sc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug49nnn/bug49297DuplicateAttr.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(500, sc);
|
||||
}
|
||||
|
||||
/** Assertion for text printed by tags:echo */
|
||||
private static void assertEcho(String result, String expected) {
|
||||
Assert.assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
|
||||
}
|
||||
}
|
||||
99
test/org/apache/jasper/compiler/TestScriptingVariabler.java
Normal file
99
test/org/apache/jasper/compiler/TestScriptingVariabler.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.jsp.tagext.TagData;
|
||||
import javax.servlet.jsp.tagext.TagExtraInfo;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
import javax.servlet.jsp.tagext.VariableInfo;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
|
||||
public class TestScriptingVariabler extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug42390() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug42390.jsp");
|
||||
} catch (IOException ioe) {
|
||||
e = ioe;
|
||||
}
|
||||
|
||||
// Should not fail
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
|
||||
public static class Bug48616aTag extends TagSupport {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public static class Bug48616bTag extends TagSupport {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public static class Bug48616bTei extends TagExtraInfo {
|
||||
/**
|
||||
* Return information about the scripting variables to be created.
|
||||
*/
|
||||
@Override
|
||||
public VariableInfo[] getVariableInfo(TagData data) {
|
||||
return new VariableInfo[] {
|
||||
new VariableInfo("Test", "java.lang.String", true,
|
||||
VariableInfo.AT_END)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48616() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug48nnn/bug48616.jsp");
|
||||
} catch (IOException ioe) {
|
||||
e = ioe;
|
||||
}
|
||||
|
||||
// Should not fail
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48616b() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
getUrl("http://localhost:" + getPort() + "/test/bug48nnn/bug48616b.jsp");
|
||||
} catch (IOException ioe) {
|
||||
e = ioe;
|
||||
}
|
||||
|
||||
// Should not fail
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
}
|
||||
43
test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
Normal file
43
test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
/**
|
||||
* Test case for {@link TagLibraryInfoImpl}.
|
||||
*/
|
||||
public class TestTagLibraryInfoImpl extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testRelativeTldLocation() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
ByteChunk res = new ByteChunk();
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/jsp/test.jsp", res, null);
|
||||
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
|
||||
}
|
||||
|
||||
}
|
||||
71
test/org/apache/jasper/compiler/TestTagPluginManager.java
Normal file
71
test/org/apache/jasper/compiler/TestTagPluginManager.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.jsp.tagext.TagFileInfo;
|
||||
import javax.servlet.jsp.tagext.TagInfo;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
|
||||
/**
|
||||
* Test case for {@link TagPluginManager}.
|
||||
*/
|
||||
public class TestTagPluginManager extends TomcatBaseTest {
|
||||
|
||||
private static TagInfo tagInfo = new TagInfo("ATag",
|
||||
"org.apache.jasper.compiler.ATagSupport", "", "", null, null, null);
|
||||
|
||||
@Test
|
||||
public void testBug54240() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
|
||||
|
||||
ServletContext context = ((Context) tomcat.getHost().findChildren()[0]).getServletContext();
|
||||
|
||||
TagPluginManager manager = new TagPluginManager(context);
|
||||
|
||||
Node.Nodes nodes = new Node.Nodes();
|
||||
Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag",
|
||||
"http://tomcat.apache.org/jasper", null, null, null, null, null,
|
||||
new TagFileInfo("ATag", "http://tomcat.apache.org/jasper",
|
||||
tagInfo));
|
||||
c.setTagHandlerClass(TesterTag.class);
|
||||
nodes.add(c);
|
||||
manager.apply(nodes, null, null);
|
||||
|
||||
Node n = nodes.getNode(0);
|
||||
Assert.assertNotNull(n);
|
||||
Assert.assertTrue(n instanceof Node.CustomTag);
|
||||
|
||||
Node.CustomTag t = (Node.CustomTag)n;
|
||||
Assert.assertNotNull(t.getAtSTag());
|
||||
|
||||
Node.Nodes sTag = c.getAtSTag();
|
||||
Node scriptlet = sTag.getNode(0);
|
||||
Assert.assertNotNull(scriptlet);
|
||||
Assert.assertTrue(scriptlet instanceof Node.Scriptlet);
|
||||
Node.Scriptlet s = (Node.Scriptlet)scriptlet;
|
||||
Assert.assertEquals("//Just a comment", s.getText());
|
||||
}
|
||||
}
|
||||
220
test/org/apache/jasper/compiler/TestValidator.java
Normal file
220
test/org/apache/jasper/compiler/TestValidator.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.startup.TomcatBaseTest;
|
||||
import org.apache.tomcat.util.buf.ByteChunk;
|
||||
|
||||
public class TestValidator extends TomcatBaseTest {
|
||||
|
||||
@Test
|
||||
public void testBug47331() throws Exception {
|
||||
getTomcatInstanceTestWebapp(false, true);
|
||||
|
||||
int rc = getUrl("http://localhost:" + getPort() +
|
||||
"/test/bug47331.jsp", new ByteChunk(), null);
|
||||
|
||||
Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions22() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-2.2");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>${'00-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'02-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'04-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'06-hello world'}</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions23() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-2.3");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>${'00-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'02-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'04-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>${'06-hello world'}</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions24() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-2.4");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions25() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-2.5");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions30() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-3.0");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTldVersions31() throws Exception {
|
||||
Tomcat tomcat = getTomcatInstance();
|
||||
|
||||
File appDir =
|
||||
new File("test/webapp-3.1");
|
||||
// app dir is relative to server home
|
||||
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
|
||||
|
||||
tomcat.start();
|
||||
|
||||
ByteChunk res = getUrl("http://localhost:" + getPort() +
|
||||
"/test/tld-versions.jsp");
|
||||
|
||||
String result = res.toString();
|
||||
|
||||
Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
|
||||
Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
|
||||
}
|
||||
|
||||
public static class Echo extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String echo = null;
|
||||
|
||||
public void setEcho(String echo) {
|
||||
this.echo = echo;
|
||||
}
|
||||
|
||||
public String getEcho() {
|
||||
return echo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doStartTag() throws JspException {
|
||||
try {
|
||||
pageContext.getOut().print("<p>" + echo + "</p>");
|
||||
} catch (IOException e) {
|
||||
pageContext.getServletContext().log("Tag (Echo21) failure", e);
|
||||
}
|
||||
return super.doStartTag();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
test/org/apache/jasper/compiler/TesterTag.java
Normal file
28
test/org/apache/jasper/compiler/TesterTag.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
/**
|
||||
* A tag for test purpose
|
||||
*/
|
||||
public class TesterTag extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
31
test/org/apache/jasper/compiler/TesterTagPlugin.java
Normal file
31
test/org/apache/jasper/compiler/TesterTagPlugin.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.apache.jasper.compiler.tagplugin.TagPlugin;
|
||||
import org.apache.jasper.compiler.tagplugin.TagPluginContext;
|
||||
|
||||
/**
|
||||
* Plug-in for {@link TesterTag}.
|
||||
*/
|
||||
public class TesterTagPlugin implements TagPlugin {
|
||||
|
||||
@Override
|
||||
public void doTag(TagPluginContext ctxt) {
|
||||
ctxt.generateJavaSource("//Just a comment");
|
||||
}
|
||||
}
|
||||
102
test/org/apache/jasper/compiler/TesterValidator.java
Normal file
102
test/org/apache/jasper/compiler/TesterValidator.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jasper.compiler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.tomcat.util.security.Escape;
|
||||
|
||||
/**
|
||||
* Performance tests for {@link Validator}.
|
||||
*/
|
||||
public class TesterValidator {
|
||||
|
||||
private static String[] bug53867TestData = new String[] {
|
||||
"Hello World!",
|
||||
"<meta http-equiv=\"Content-Language\">",
|
||||
"This connection has limited network connectivity.",
|
||||
"Please use this web page & to access file server resources." };
|
||||
|
||||
@Test
|
||||
public void testBug53867() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
doTestBug53867();
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTestBug53867() {
|
||||
int count = 100000;
|
||||
|
||||
for (int j = 0; j < bug53867TestData.length; j++) {
|
||||
Assert.assertEquals(doTestBug53867OldVersion(bug53867TestData[j]),
|
||||
Escape.xml(bug53867TestData[j]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int j = 0; j < bug53867TestData.length; j++) {
|
||||
doTestBug53867OldVersion(bug53867TestData[j]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int j = 0; j < bug53867TestData.length; j++) {
|
||||
Escape.xml(bug53867TestData[j]);
|
||||
}
|
||||
}
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int j = 0; j < bug53867TestData.length; j++) {
|
||||
doTestBug53867OldVersion(bug53867TestData[j]);
|
||||
}
|
||||
}
|
||||
System.out.println(
|
||||
"Old escape:" + (System.currentTimeMillis() - start));
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int j = 0; j < bug53867TestData.length; j++) {
|
||||
Escape.xml(bug53867TestData[j]);
|
||||
}
|
||||
}
|
||||
System.out.println(
|
||||
"New escape:" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
private static String doTestBug53867OldVersion(String s) {
|
||||
if (s == null)
|
||||
return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '<') {
|
||||
sb.append("<");
|
||||
} else if (c == '>') {
|
||||
sb.append(">");
|
||||
} else if (c == '\'') {
|
||||
sb.append("'"); // '
|
||||
} else if (c == '&') {
|
||||
sb.append("&");
|
||||
} else if (c == '"') {
|
||||
sb.append("""); // "
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user