This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new f29c6939de Review "Avoid StringIndexOutOfBoundsException forwarding
..."
f29c6939de is described below
commit f29c6939de174e6c400cd38a7e54a11dfc782ec3
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Nov 6 09:19:46 2026 +0000
Review "Avoid StringIndexOutOfBoundsException forwarding ..."
Remove duplicate code.
Fix similar issue in tag plug-ins
Co-authored by: Claude / Sonnet 5.5
---
java/org/apache/jasper/runtime/PageContextImpl.java | 19 +------------------
.../apache/jasper/tagplugins/jstl/core/Import.java | 8 ++++++--
2 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java
b/java/org/apache/jasper/runtime/PageContextImpl.java
index 2044f7a497..6c935dfdbe 100644
--- a/java/org/apache/jasper/runtime/PageContextImpl.java
+++ b/java/org/apache/jasper/runtime/PageContextImpl.java
@@ -441,23 +441,6 @@ public class PageContextImpl extends PageContext {
return servlet;
}
- private String getAbsolutePathRelativeToContext(String relativeUrlPath) {
- String path = relativeUrlPath;
-
- if (!path.startsWith("/")) {
- String uri = (String)
request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
- if (uri == null) {
- uri = ((HttpServletRequest) request).getServletPath();
- }
- if (uri.lastIndexOf('/') >= 0) {
- uri = uri.substring(0, uri.lastIndexOf('/'));
- }
- path = uri + '/' + path;
- }
-
- return path;
- }
-
@Override
public void include(String relativeUrlPath) throws ServletException,
IOException {
JspRuntimeLibrary.include(request, response, relativeUrlPath, out,
true);
@@ -489,7 +472,7 @@ public class PageContextImpl extends PageContext {
response = ((ServletResponseWrapperInclude)
response).getResponse();
}
- final String path = getAbsolutePathRelativeToContext(relativeUrlPath);
+ final String path = JspRuntimeLibrary.getContextRelativePath(request,
relativeUrlPath);
String includeUri = (String)
request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
if (includeUri != null) {
diff --git a/java/org/apache/jasper/tagplugins/jstl/core/Import.java
b/java/org/apache/jasper/tagplugins/jstl/core/Import.java
index e4d2ca2dc4..3bfe051689 100644
--- a/java/org/apache/jasper/tagplugins/jstl/core/Import.java
+++ b/java/org/apache/jasper/tagplugins/jstl/core/Import.java
@@ -132,8 +132,12 @@ public class Import implements TagPlugin {
ctxt.generateJavaSource(" if(!" + urlName + ".startsWith(\"/\")){");
ctxt.generateJavaSource(" String " + servletPathName + " = " +
"((HttpServletRequest)_jspx_page_context.getRequest()).getServletPath();");
- ctxt.generateJavaSource(" " + urlName + " = " + servletPathName
+ ".substring(0," + servletPathName +
- ".lastIndexOf('/')) + '/' + " + urlName + ";");
+ // The servlet path may contain no '/' (e.g. the empty string for the
empty url-pattern)
+ ctxt.generateJavaSource(" if(" + servletPathName +
".lastIndexOf('/') >= 0){");
+ ctxt.generateJavaSource(" " + servletPathName + " = " +
servletPathName + ".substring(0," +
+ servletPathName + ".lastIndexOf('/'));");
+ ctxt.generateJavaSource(" }");
+ ctxt.generateJavaSource(" " + urlName + " = " + servletPathName
+ " + '/' + " + urlName + ";");
ctxt.generateJavaSource(" }");
ctxt.generateJavaSource("}");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]