This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit d9edf86e2629904c5bdb51d0bdf98acb82dd5d88 Author: opencode <[email protected]> AuthorDate: Mon Oct 19 09:55:49 2026 +0200 Omit the id from validation messages without one Validator.validateXmlView() appended the id of each ValidationMessage returned by a TagLibraryValidator followed by a separator unconditionally before the message. The JSP specification and the ValidationMessage javadoc allow the id to be null, meaning that no jsp:id information is available, so a validator returning such a message produced an error report containing the literal text "null: " in front of the message. Render the id the same way the parallel TagExtraInfoVisitor path already does: only when it is present. The regression test also pins the unchanged rendering for a message that does have an id. Found by code review. --- java/org/apache/jasper/compiler/Validator.java | 6 ++-- test/org/apache/jasper/compiler/TestValidator.java | 33 ++++++++++++++++++++++ test/webapp/WEB-INF/null-id-tlv.tld | 28 ++++++++++++++++++ test/webapp/jsp/parsing/taglib-null-id-tlv.jsp | 24 ++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/java/org/apache/jasper/compiler/Validator.java b/java/org/apache/jasper/compiler/Validator.java index 05eed675e3..debff4e913 100644 --- a/java/org/apache/jasper/compiler/Validator.java +++ b/java/org/apache/jasper/compiler/Validator.java @@ -1683,8 +1683,10 @@ class Validator { for (ValidationMessage error : errors) { if (error != null) { errMsg.append("<p>"); - errMsg.append(error.getId()); - errMsg.append(": "); + if (error.getId() != null) { + errMsg.append(error.getId()); + errMsg.append(": "); + } errMsg.append(error.getMessage()); errMsg.append("</p>"); } diff --git a/test/org/apache/jasper/compiler/TestValidator.java b/test/org/apache/jasper/compiler/TestValidator.java index 17c2523492..2fd7c6cf15 100644 --- a/test/org/apache/jasper/compiler/TestValidator.java +++ b/test/org/apache/jasper/compiler/TestValidator.java @@ -21,7 +21,10 @@ import java.io.IOException; import javax.servlet.http.HttpServletResponse; import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.PageData; +import javax.servlet.jsp.tagext.TagLibraryValidator; import javax.servlet.jsp.tagext.TagSupport; +import javax.servlet.jsp.tagext.ValidationMessage; import org.junit.Assert; import org.junit.Test; @@ -59,6 +62,27 @@ public class TestValidator extends TomcatBaseTest { Assert.assertFalse(result, result.contains("NumberFormatException")); } + @Test + public void testNullIdTlv() throws Exception { + getTomcatInstanceTestWebapp(false, true); + + ByteChunk res = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + "/test/jsp/parsing/taglib-null-id-tlv.jsp", res, null); + + Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc); + + // The validator returns a ValidationMessage with a null id. The id + // and the following separator must be omitted from the reported + // message. They were previously appended unconditionally which + // rendered the literal text "null: " in front of the message. + String result = res.toString(); + Assert.assertTrue(result, result.contains("message without an id")); + Assert.assertFalse(result, result.contains("null: message")); + // The id of a ValidationMessage that has one is still reported + Assert.assertTrue(result, result.contains("123: message with an id")); + } + @Test public void testTldVersions22() throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -220,6 +244,15 @@ public class TestValidator extends TomcatBaseTest { Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0); } + public static class NullIdValidator extends TagLibraryValidator { + + @Override + public ValidationMessage[] validate(String prefix, String uri, PageData page) { + return new ValidationMessage[] { new ValidationMessage(null, "message without an id"), + new ValidationMessage("123", "message with an id") }; + } + } + public static class Echo extends TagSupport { private static final long serialVersionUID = 1L; diff --git a/test/webapp/WEB-INF/null-id-tlv.tld b/test/webapp/WEB-INF/null-id-tlv.tld new file mode 100644 index 0000000000..e3d813b8e0 --- /dev/null +++ b/test/webapp/WEB-INF/null-id-tlv.tld @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<taglib xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" + version="2.1"> + <tlib-version>1.0</tlib-version> + <short-name>nlid</short-name> + <uri>http://tomcat.apache.org/null-id-tlv</uri> + <validator> + <validator-class>org.apache.jasper.compiler.TestValidator$NullIdValidator</validator-class> + </validator> +</taglib> diff --git a/test/webapp/jsp/parsing/taglib-null-id-tlv.jsp b/test/webapp/jsp/parsing/taglib-null-id-tlv.jsp new file mode 100644 index 0000000000..ac58d59086 --- /dev/null +++ b/test/webapp/jsp/parsing/taglib-null-id-tlv.jsp @@ -0,0 +1,24 @@ +<%-- + 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 contentType="text/html;charset=UTF-8" %> +<%@ taglib uri="/WEB-INF/null-id-tlv.tld" prefix="nlid" %> +<html> + <head><title>Tag library validator with a null id test case</title></head> + <body> + <p>Should fail</p> + </body> +</html> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
