This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 44dc1c19a6 Fix BZ 66441 - Make imports of static fields in JSPs visible to EL 44dc1c19a6 is described below commit 44dc1c19a601c0ddf902d7ab0951024ee094381e Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Feb 1 14:49:27 2023 +0000 Fix BZ 66441 - Make imports of static fields in JSPs visible to EL https://bz.apache.org/bugzilla/show_bug.cgi?id=66441 --- .../org/apache/jasper/runtime/PageContextImpl.java | 7 +++- .../servlet/jsp/el/TestImportELResolver.java | 39 ++++++++++++++++++++++ test/webapp/bug6nnnn/bug66441.jsp | 23 +++++++++++++ webapps/docs/changelog.xml | 4 +++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java b/java/org/apache/jasper/runtime/PageContextImpl.java index e3388f0aa7..26d313de08 100644 --- a/java/org/apache/jasper/runtime/PageContextImpl.java +++ b/java/org/apache/jasper/runtime/PageContextImpl.java @@ -696,7 +696,12 @@ public class PageContextImpl extends PageContext { Set<String> classImports = ((JspSourceImports) servlet).getClassImports(); if (classImports != null) { for (String classImport : classImports) { - ih.importClass(classImport); + if (classImport.startsWith("static ")) { + classImport = classImport.substring(7); + ih.importStatic(classImport); + } else { + ih.importClass(classImport); + } } } } diff --git a/test/jakarta/servlet/jsp/el/TestImportELResolver.java b/test/jakarta/servlet/jsp/el/TestImportELResolver.java new file mode 100644 index 0000000000..b68529d821 --- /dev/null +++ b/test/jakarta/servlet/jsp/el/TestImportELResolver.java @@ -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 jakarta.servlet.jsp.el; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestImportELResolver extends TomcatBaseTest { + + // https://bz.apache.org/bugzilla/show_bug.cgi?id=66441 + @Test + public void testImportStaticFields() throws Exception { + getTomcatInstanceTestWebapp(false, true); + + ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug66441.jsp"); + + String result = res.toString(); + + Assert.assertTrue(result.contains("EL - Long min value is -9223372036854775808")); + Assert.assertTrue(result.contains("JSP - Long min value is -9223372036854775808")); + } +} diff --git a/test/webapp/bug6nnnn/bug66441.jsp b/test/webapp/bug6nnnn/bug66441.jsp new file mode 100644 index 0000000000..ecc45c71bc --- /dev/null +++ b/test/webapp/bug6nnnn/bug66441.jsp @@ -0,0 +1,23 @@ +<%-- + 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. +--%> +<%@ page import="static java.lang.Long.MIN_VALUE"%> +<html> + <body> + <p>EL - Long min value is ${MIN_VALUE}</p> + <p>JSP - Long min value is <%= MIN_VALUE %></p> + </body> +</html> \ No newline at end of file diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 7f09b0c3d2..156b1a5c6d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -156,6 +156,10 @@ Log basic information for each configured TLS certificate when Tomcat starts. (markt) </add> + <fix> + <bug>66441</bug>: Make imports of static fields in JSPs visible to any + EL expressions used on the page. (markt) + </fix> <fix> <bug>66442</bug>: When an HTTP/2 response must not include a body, ensure that the end of stream flag is set on the headers frame and that --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org