This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 380eb782f9d60b941074349fa7d7046fb312f2ec
Author: opencode <[email protected]>
AuthorDate: Mon Oct 19 09:37:58 2026 +0200

    Report a translation error for an empty taglib URI
    
    A classic syntax page using <%@ taglib uri="" prefix="p" %> passed the
    null checks in Parser.parseTaglibDirective() with an empty string, so
    generateTldResourcePath() evaluated uri.charAt(0) on a zero-length
    string. The resulting StringIndexOutOfBoundsException was only caught
    by the generic RuntimeException handler in Compiler.generateJava(), so
    the page failed with a raw runtime exception instead of a JSP
    translation error.
    
    The XML syntax path could reach the same code by supplying an empty
    namespace remainder, for example xmlns:p="urn:jsptld:", since the
    plain URI handling in JspDocumentParser does not apply once the
    urn:jsptld: prefix has been removed.
    
    Reject an empty URI at the start of generateTldResourcePath() with the
    existing jsp.error.taglibDirective.uriInvalid message, which is the
    same error used by the sibling branches for malformed URIs.
    
    Found by code review.
---
 .../apache/jasper/compiler/TagLibraryInfoImpl.java |  4 ++++
 .../jasper/compiler/TestTagLibraryInfoImpl.java    | 18 ++++++++++++++++
 test/webapp/jsp/parsing/taglib-empty-uri.jsp       | 24 ++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java 
b/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java
index 02aae498a4..7d02e5f8cb 100644
--- a/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java
+++ b/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java
@@ -228,6 +228,10 @@ class TagLibraryInfoImpl extends TagLibraryInfo implements 
TagConstants {
      */
     private TldResourcePath generateTldResourcePath(String uri, 
JspCompilationContext ctxt) throws JasperException {
 
+        if (uri.isEmpty()) {
+            err.jspError("jsp.error.taglibDirective.uriInvalid", uri);
+        }
+
         // TODO: this matches the current implementation but the URL logic 
looks fishy
         // map URI to location per JSP 7.3.6.2
         if (uri.indexOf(':') != -1) {
diff --git a/test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java 
b/test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
index a9caf237fa..c830607a58 100644
--- a/test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
+++ b/test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
@@ -55,6 +55,24 @@ public class TestTagLibraryInfoImpl extends TomcatBaseTest {
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
     }
 
+    @Test
+    public void testEmptyTaglibUri() throws Exception {
+        getTomcatInstanceTestWebapp(false, true);
+
+        ByteChunk res = new ByteChunk();
+
+        int rc = getUrl("http://localhost:"; + getPort() + 
"/test/jsp/parsing/taglib-empty-uri.jsp", res, null);
+        Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
+
+        // An empty taglib URI must produce a clean translation error. It
+        // previously triggered a StringIndexOutOfBoundsException in
+        // TagLibraryInfoImpl.generateTldResourcePath() that was reported
+        // instead of the translation error.
+        String result = res.toString();
+        Assert.assertTrue(result, result.contains("is not a valid URI"));
+        Assert.assertFalse(result, 
result.contains("StringIndexOutOfBoundsException"));
+    }
+
     /*
      * https://bz.apache.org/bugzilla/show_bug.cgi?id=64373
      */
diff --git a/test/webapp/jsp/parsing/taglib-empty-uri.jsp 
b/test/webapp/jsp/parsing/taglib-empty-uri.jsp
new file mode 100644
index 0000000000..b407e0c540
--- /dev/null
+++ b/test/webapp/jsp/parsing/taglib-empty-uri.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="" prefix="p" %>
+<html>
+  <head><title>Taglib with an empty URI test case</title></head>
+  <body>
+    <p>Should fail</p>
+  </body>
+</html>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to