remm        01/09/14 09:45:33

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        WebdavServlet.java
  Log:
  - Forgot to backport some code from Slide.
  - Now, the protocol name is not hardcoded when parsing a destination header,
    so it fixes problems when using https. The parsing code is also more robust.
  - Fixes bug 3613.
  
  Revision  Changes    Path
  1.25      +33 -13    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
  
  Index: WebdavServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- WebdavServlet.java        2001/09/07 05:48:30     1.24
  +++ WebdavServlet.java        2001/09/14 16:45:33     1.25
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
 1.24 2001/09/07 05:48:30 remm Exp $
  - * $Revision: 1.24 $
  - * $Date: 2001/09/07 05:48:30 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
 1.25 2001/09/14 16:45:33 remm Exp $
  + * $Revision: 1.25 $
  + * $Date: 2001/09/14 16:45:33 $
    *
    * ====================================================================
    *
  @@ -126,7 +126,7 @@
    * are handled by the DefaultServlet.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.24 $ $Date: 2001/09/07 05:48:30 $
  + * @version $Revision: 1.25 $ $Date: 2001/09/14 16:45:33 $
    */
   
   public class WebdavServlet
  @@ -1498,21 +1498,41 @@
   
           String destinationPath = req.getHeader("Destination");
   
  -        if (destinationPath.startsWith("http://";)) {
  -            destinationPath = destinationPath.substring("http://".length());
  -        }
  -
  -        String hostName = req.getServerName();
  -        if ((hostName != null) && (destinationPath.startsWith(hostName))) {
  -            destinationPath = destinationPath.substring(hostName.length());
  +        if (destinationPath == null) {
  +            resp.sendError(WebdavStatus.SC_BAD_REQUEST);
  +            return false;
           }
   
  -        if (destinationPath.startsWith(":")) {
  -            int firstSeparator = destinationPath.indexOf('/');
  +        int protocolIndex = destinationPath.indexOf("://");
  +        if (protocolIndex >= 0) {
  +            // if the Destination URL contains the protocol, we can safely
  +            // trim everything upto the first "/" character after "://"
  +            int firstSeparator =
  +                destinationPath.indexOf("/", protocolIndex + 4);
               if (firstSeparator < 0) {
                   destinationPath = "/";
               } else {
                   destinationPath = destinationPath.substring(firstSeparator);
  +            }
  +        } else {
  +            String hostName = req.getServerName();
  +            if ((hostName != null) && (destinationPath.startsWith(hostName))) {
  +                destinationPath = destinationPath.substring(hostName.length());
  +            }
  +
  +            int portIndex = destinationPath.indexOf(":");
  +            if (portIndex >= 0) {
  +                destinationPath = destinationPath.substring(portIndex);
  +            }
  +
  +            if (destinationPath.startsWith(":")) {
  +                int firstSeparator = destinationPath.indexOf("/");
  +                if (firstSeparator < 0) {
  +                    destinationPath = "/";
  +                } else {
  +                    destinationPath = 
  +                        destinationPath.substring(firstSeparator);
  +                }
               }
           }
   
  
  
  

Reply via email to