Fix response.encodeURL() for the special case of
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 5 Jul 2011 10:08:00 +0000 (10:08 +0000)
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 5 Jul 2011 10:08:00 +0000 (10:08 +0000)
an absolute URL with no path segment (http://name).

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1142959 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/Response.java
webapps/docs/changelog.xml

index df7d8fa..6b8ca7b 100644 (file)
@@ -1198,8 +1198,10 @@ public class Response
         String absolute = toAbsolute(url);
         if (isEncodeable(absolute)) {
             // W3c spec clearly said 
-            if (url.equalsIgnoreCase("")){
+            if (url.equalsIgnoreCase("")) {
                 url = absolute;
+            } else if (url.equals(absolute) && !hasPath(url)) {
+                url += '/';
             }
             return (toEncoded(url, request.getSessionInternal().getIdInternal()));
         } else {
@@ -1648,6 +1650,21 @@ public class Response
 
 
     /**
+     * Determine if an absolute URL has a path component
+     */
+    private boolean hasPath(String uri) {
+        int pos = uri.indexOf("://");
+        if (pos < 0) {
+            return false;
+        }
+        pos = uri.indexOf('/', pos + 3);
+        if (pos < 0) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
      * Determine if a URI string has a <code>scheme</code> component.
      */
     private boolean hasScheme(String uri) {
index 1948706..04cf301 100644 (file)
         <bug>51473</bug>: Fix concatenation of values in
         <code>SecurityConfig.setSecurityProperty()</code>. (kkolinko)
       </fix>
+      <fix>
+        Fix response.encodeURL() for the special case of an absolute URL
+        with no path segment (http://name). (rjung)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">