You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2007/11/29 01:39:55 UTC

svn commit: r599226 - /myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java

Author: sobryan
Date: Wed Nov 28 16:39:53 2007
New Revision: 599226

URL: http://svn.apache.org/viewvc?rev=599226&view=rev
Log:
PORTLETBRIDGE-16: Path problems in PortletExternalContextImpl.

Patch submitted by Mike Freedman.  Thanks!

Modified:
    myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java

Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=599226&r1=599225&r2=599226&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java Wed Nov 28 16:39:53 2007
@@ -429,6 +429,11 @@
       path = path.substring(0, path.lastIndexOf("/"));
       s = URLUtils.convertFromRelative(path, s);
     }
+    
+    // prepend the context path since portletResponse.encodeURL() requires a full path URI
+    // Don't need to check return from getRequestContextPath because there must
+    // always be a vlaue even if an empty string
+    s = getRequestContextPath() + s;
 
     String resourceURLStr = mPortletResponse.encodeURL(s);
 
@@ -1253,23 +1258,29 @@
   
   private boolean isAbsoluteURL(String url)
   {
-    if (url.startsWith("http"))
+    // Quick check for most common case
+    if (url.startsWith("http:") || url.startsWith("https:"))
     {
       return true;
     }
 
-    // now deal with other possible protocols
+    // now deal with other possible protocols -- find the potential scheme
     int i = url.indexOf(":");
     if (i == -1)
     {
       return false;
     }
-    int j = url.indexOf("/");
-    if (j != -1 && j > i)
-    {
-      return true;
-    }
-    return false;
+
+    // Now make sure that the  substring before the : is a valid scheme
+    // i.e. contains no URI reserved characters
+    String scheme = url.substring(0, i);
+
+    if (scheme.indexOf(";") != -1) return false;
+    else if (scheme.indexOf("/") != -1) return false;
+    else if (scheme.indexOf("#") != -1) return false;
+    else if (scheme.indexOf("?") != -1) return false;
+    else if (scheme.indexOf(" ") != -1) return false;
+    else return true; 
   }
 
   private boolean isExternalURL(String url)