You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/04/06 01:29:59 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/servlets DefaultServlet.java
craigmcc 00/04/05 16:29:59
Modified: src/share/org/apache/tomcat/request SimpleMapper.java
src/share/org/apache/tomcat/servlets DefaultServlet.java
Log:
Correct a spec compliance bug in the way extension mapping was
implemented. Previously, a request for
http://localhost:8080/examples/jsp/snoop.jsp/foo
was being resolved to the /examples/jsp/snoop.jsp JSP page, and passing a
path info value of "/foo". This is contrary to the servlet specification
version 2.2, section 10.1, bullet point 3:
If the last node of the url-path contains an
extension (.jsp for example), the servlet
container will try to match a servlet that handles
requests for that extension. An extension is
defined as the part of the path after the last
'.' character.
Now, the request shown above will return a 404 error (file not found).
This also required fixing a bug in DefaultFileServlet that would throw an
IOException ("bad file path") on the above request, because
getCanonicalPath() choked when it tried to treat the "snoop.jsp" part as a
directory, when it was actually a file.
Also fixed an additional bug in DefaultFileServlet, which was gluing
together the document root (with a '/' appended) and the path information
from the request, resulting in two slashes in a row. Apparently most OS's
ignored this (or the underlying JVM fixed it transparently), but it's
better to be correct.
Watchdog runs 100% against this revised code.
Revision Changes Path
1.17 +7 -0 jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java
Index: SimpleMapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SimpleMapper.java 2000/03/21 01:27:09 1.16
+++ SimpleMapper.java 2000/04/05 23:29:58 1.17
@@ -445,6 +445,12 @@
int i = path.lastIndexOf(".");
int j = path.lastIndexOf("/");
+ if ((i > 0) && (i > j))
+ return path.substring(i);
+ else
+ return null;
+
+ /*
if (i > -1) {
String extension = path.substring(i);
int k = extension.indexOf("/");
@@ -453,6 +459,7 @@
return extension;
}
return null;
+ */
}
private String removeLast( String s) {
1.12 +14 -2 jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultServlet.java
Index: DefaultServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DefaultServlet.java 2000/03/29 23:31:06 1.11
+++ DefaultServlet.java 2000/04/05 23:29:59 1.12
@@ -124,7 +124,11 @@
}
// Clean up pathInfo
- File file = new File(docBase + pathInfo);
+ File file = null;
+ if ((pathInfo == null) || (pathInfo.length() < 1))
+ file = new File(docBase);
+ else // Avoid double slashes because docBase ends with one
+ file = new File(docBase + pathInfo.substring(1));
String absPath = file.getAbsolutePath();
if( debug > 0 ) contextF.log( "DefaultServlet: " + absPath);
@@ -237,7 +241,15 @@
throws IOException {
String absPath = file.getAbsolutePath();
- String canPath = file.getCanonicalPath();
+ String canPath = null;
+ try {
+ canPath = file.getCanonicalPath();
+ } catch (IOException e) {
+ // Normally caused by arbitrary path info contents
+ response.sendError(response.SC_NOT_FOUND,
+ "File Not Found<br>" + request.getRequestURI());
+ return;
+ }
// take care of File.getAbsolutePath() troubles on
// jdk1.1.x/win