From 3b239b23eec10422a549e1e41ea355bac064b866 Mon Sep 17 00:00:00 2001 From: Chenjp Date: Mon, 23 Dec 2024 01:12:01 +0800 Subject: [PATCH 1/3] Fix BZ69508 In GeneratorVisitor#generateIncludeWithParameters, since we introduce an extra variable urlVariableName to store include page param, then we need explicit specify literal=true when call #printParams. --- .../org/apache/jasper/compiler/Generator.java | 2 +- .../apache/jasper/compiler/TestGenerator.java | 31 +++++++++ test/webapp/bug6nnnn/bug69508.jsp | 65 +++++++++++++++++++ .../webapp/bug6nnnn/bug69508_inc_absolute.jsp | 20 ++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/webapp/bug6nnnn/bug69508.jsp create mode 100644 test/webapp/bug6nnnn/bug69508_inc_absolute.jsp diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index 4eb9deb893f1..ec18bc92ee71 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -1108,7 +1108,7 @@ private void generateIncludeWithParameters(Node.IncludeAction n, Node.JspAttribu out.printin("String " + requestEncodingVariableName + " = " + REQUEST_CHARACTER_ENCODING_TEXT + ";"); out.println(); out.printin("org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, " + urlVariableName); - printParams(n, urlVariableName, page.isLiteral(), requestEncodingVariableName); + printParams(n, urlVariableName, false, requestEncodingVariableName); out.println(", out, " + isFlush + ");"); } diff --git a/test/org/apache/jasper/compiler/TestGenerator.java b/test/org/apache/jasper/compiler/TestGenerator.java index 892e398660b3..70e8e18ff3b9 100644 --- a/test/org/apache/jasper/compiler/TestGenerator.java +++ b/test/org/apache/jasper/compiler/TestGenerator.java @@ -971,6 +971,37 @@ public void testBug65390() throws Exception { Assert.assertEquals(body.toString(), HttpServletResponse.SC_OK, rc); } + @Test + public void testBug69508() throws Exception { + getTomcatInstanceTestWebapp(false, true); + + ByteChunk body = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug69508.jsp?init=InitCommand", body, null); + + String text = body.toString(); + Assert.assertEquals(text, HttpServletResponse.SC_OK, rc); + // include page URL with param cmd + Assert.assertTrue(text, text.contains("

cmd - someCommand

")); + Assert.assertTrue(text, text.contains("

param1 - value1

")); + Assert.assertTrue(text, text.contains("

cmd - someCommandAbs

")); + Assert.assertTrue(text, text.contains("

param1 - value1Abs

")); + // include page URL without param + Assert.assertTrue(text, text.contains("

param2 - value2

")); + Assert.assertTrue(text, text.contains("

param2 - value2Abs

")); + + Assert.assertTrue(text, text.contains("

param3 - InitCommand

")); + Assert.assertTrue(text, text.contains("

param3 - InitCommandAbs

")); + + Assert.assertTrue(text, text.contains("

param4 - value4

")); + Assert.assertTrue(text, text.contains("

param4 - value4Abs

")); + + Assert.assertTrue(text, text.contains("

param5 - InitCommand

")); + Assert.assertTrue(text, text.contains("

param5 - InitCommandAbs

")); + + Assert.assertTrue(text, text.contains("

param6 - value6

")); + Assert.assertTrue(text, text.contains("

param6 - value6Abs

")); + } + @Test public void testTagReleaseWithPooling() throws Exception { doTestTagRelease(true); diff --git a/test/webapp/bug6nnnn/bug69508.jsp b/test/webapp/bug6nnnn/bug69508.jsp new file mode 100644 index 000000000000..3784d0e51885 --- /dev/null +++ b/test/webapp/bug6nnnn/bug69508.jsp @@ -0,0 +1,65 @@ +<%-- + 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. +--%> + + + + + + + + + + + + + + + + + +<%-- + Verify expression support in page and param value. + --%> +<% + String initCommand = request.getParameter("init"); + if (initCommand != null) { + String relativeUrl = "../echo-params.jsp?param3=" + initCommand; + String absoluteUrl = "/echo-params.jsp?param3=" + initCommand + "Abs"; + String init_param = initCommand+"_param"; + String init_param_value_abs=initCommand+"Abs"; + %> + + + + + + + + + + <% + } +%> +<%-- +Following cases without jsp:param +--%> + + + + + + \ No newline at end of file diff --git a/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp b/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp new file mode 100644 index 000000000000..856fc8e77e49 --- /dev/null +++ b/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp @@ -0,0 +1,20 @@ +<%-- + 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. +--%> +<% +out.println("Key=cmd;Value="+request.getParameter("cmd")); +out.println("Key=param1;Value="+request.getParameter("param1")); +%> \ No newline at end of file From 8b09bb6476548ea23ed7795fdba62e25ff9a107d Mon Sep 17 00:00:00 2001 From: Chenjp Date: Mon, 23 Dec 2024 01:12:01 +0800 Subject: [PATCH 2/3] Fix BZ69508 In GeneratorVisitor#generateIncludeWithParameters, since we introduce an extra variable urlVariableName to store include page param, then we need explicit specify literal=false when call #printParams. --- .../org/apache/jasper/compiler/Generator.java | 2 +- .../apache/jasper/compiler/TestGenerator.java | 31 +++++++++ test/webapp/bug6nnnn/bug69508.jsp | 65 +++++++++++++++++++ .../webapp/bug6nnnn/bug69508_inc_absolute.jsp | 20 ++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/webapp/bug6nnnn/bug69508.jsp create mode 100644 test/webapp/bug6nnnn/bug69508_inc_absolute.jsp diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index 4eb9deb893f1..ec18bc92ee71 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -1108,7 +1108,7 @@ private void generateIncludeWithParameters(Node.IncludeAction n, Node.JspAttribu out.printin("String " + requestEncodingVariableName + " = " + REQUEST_CHARACTER_ENCODING_TEXT + ";"); out.println(); out.printin("org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, " + urlVariableName); - printParams(n, urlVariableName, page.isLiteral(), requestEncodingVariableName); + printParams(n, urlVariableName, false, requestEncodingVariableName); out.println(", out, " + isFlush + ");"); } diff --git a/test/org/apache/jasper/compiler/TestGenerator.java b/test/org/apache/jasper/compiler/TestGenerator.java index 892e398660b3..70e8e18ff3b9 100644 --- a/test/org/apache/jasper/compiler/TestGenerator.java +++ b/test/org/apache/jasper/compiler/TestGenerator.java @@ -971,6 +971,37 @@ public void testBug65390() throws Exception { Assert.assertEquals(body.toString(), HttpServletResponse.SC_OK, rc); } + @Test + public void testBug69508() throws Exception { + getTomcatInstanceTestWebapp(false, true); + + ByteChunk body = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug69508.jsp?init=InitCommand", body, null); + + String text = body.toString(); + Assert.assertEquals(text, HttpServletResponse.SC_OK, rc); + // include page URL with param cmd + Assert.assertTrue(text, text.contains("

cmd - someCommand

")); + Assert.assertTrue(text, text.contains("

param1 - value1

")); + Assert.assertTrue(text, text.contains("

cmd - someCommandAbs

")); + Assert.assertTrue(text, text.contains("

param1 - value1Abs

")); + // include page URL without param + Assert.assertTrue(text, text.contains("

param2 - value2

")); + Assert.assertTrue(text, text.contains("

param2 - value2Abs

")); + + Assert.assertTrue(text, text.contains("

param3 - InitCommand

")); + Assert.assertTrue(text, text.contains("

param3 - InitCommandAbs

")); + + Assert.assertTrue(text, text.contains("

param4 - value4

")); + Assert.assertTrue(text, text.contains("

param4 - value4Abs

")); + + Assert.assertTrue(text, text.contains("

param5 - InitCommand

")); + Assert.assertTrue(text, text.contains("

param5 - InitCommandAbs

")); + + Assert.assertTrue(text, text.contains("

param6 - value6

")); + Assert.assertTrue(text, text.contains("

param6 - value6Abs

")); + } + @Test public void testTagReleaseWithPooling() throws Exception { doTestTagRelease(true); diff --git a/test/webapp/bug6nnnn/bug69508.jsp b/test/webapp/bug6nnnn/bug69508.jsp new file mode 100644 index 000000000000..3784d0e51885 --- /dev/null +++ b/test/webapp/bug6nnnn/bug69508.jsp @@ -0,0 +1,65 @@ +<%-- + 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. +--%> + + + + + + + + + + + + + + + + + +<%-- + Verify expression support in page and param value. + --%> +<% + String initCommand = request.getParameter("init"); + if (initCommand != null) { + String relativeUrl = "../echo-params.jsp?param3=" + initCommand; + String absoluteUrl = "/echo-params.jsp?param3=" + initCommand + "Abs"; + String init_param = initCommand+"_param"; + String init_param_value_abs=initCommand+"Abs"; + %> + + + + + + + + + + <% + } +%> +<%-- +Following cases without jsp:param +--%> + + + + + + \ No newline at end of file diff --git a/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp b/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp new file mode 100644 index 000000000000..856fc8e77e49 --- /dev/null +++ b/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp @@ -0,0 +1,20 @@ +<%-- + 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. +--%> +<% +out.println("Key=cmd;Value="+request.getParameter("cmd")); +out.println("Key=param1;Value="+request.getParameter("param1")); +%> \ No newline at end of file From c17c16f04a4b204056c755a1d9ab618541513a57 Mon Sep 17 00:00:00 2001 From: Chenjp Date: Mon, 23 Dec 2024 01:25:03 +0800 Subject: [PATCH 3/3] Delete bug69508_inc_absolute.jsp remove unused jsp file. --- .../webapp/bug6nnnn/bug69508_inc_absolute.jsp | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 test/webapp/bug6nnnn/bug69508_inc_absolute.jsp diff --git a/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp b/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp deleted file mode 100644 index 856fc8e77e49..000000000000 --- a/test/webapp/bug6nnnn/bug69508_inc_absolute.jsp +++ /dev/null @@ -1,20 +0,0 @@ -<%-- - 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. ---%> -<% -out.println("Key=cmd;Value="+request.getParameter("cmd")); -out.println("Key=param1;Value="+request.getParameter("param1")); -%> \ No newline at end of file