You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2012/08/02 01:40:59 UTC

svn commit: r1368314 - in /myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces: bridge/context/BridgeContextImpl.java context/PortletExternalContextImpl.java

Author: mfreedman
Date: Wed Aug  1 23:40:59 2012
New Revision: 1368314

URL: http://svn.apache.org/viewvc?rev=1368314&view=rev
Log:
PORTLETBRIDGE-223: Bridge mishandles encoding urls with targets containing same prefix as ContextPath.

Modified:
    myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/BridgeContextImpl.java
    myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java

Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/BridgeContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/BridgeContextImpl.java?rev=1368314&r1=1368313&r2=1368314&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/BridgeContextImpl.java (original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/BridgeContextImpl.java Wed Aug  1 23:40:59 2012
@@ -754,11 +754,10 @@ public class BridgeContextImpl extends B
     }
 
     // Now remove up through the ContextPath
-    String ctxPath = getPortletRequest().getContextPath();
-    i = path.indexOf(ctxPath);
+    i = containsContextPath(path);
     if (i != -1)
     {
-      path = path.substring(i + ctxPath.length());
+      path = path.substring(i + FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath().length());
     }
 
     String viewId = null;
@@ -832,6 +831,31 @@ public class BridgeContextImpl extends B
     
 
   }
+
+  // For use when testing whether a target contains the ContextPath or not
+
+  private int containsContextPath(String url)
+  {
+    // Make sure the
+    String ctxPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
+    int i = url.indexOf(ctxPath);
+    int q = url.indexOf('?');
+
+    if (i != -1 && i < q)
+    {
+      // make sure its actually the ContextPath and not the beginning of the target.
+      // I.e. avoid thinking /simple.jspx contains the context path when the CP is
+      // /simple
+
+      int l = ctxPath.length();
+      if (url.length() != i + l && url.charAt(i + l) != '/')
+      {
+        // Not a ContextPath
+        i = -1;
+      }
+    }
+    return i;
+  }
   
   private String getViewId(PortletRequest request, boolean excludeQueryString)
     throws BridgeDefaultViewNotSpecifiedException, BridgeInvalidViewPathException

Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=1368314&r1=1368313&r2=1368314&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java (original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java Wed Aug  1 23:40:59 2012
@@ -916,10 +916,9 @@ public class PortletExternalContextImpl
     // 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
-    String ctxPath = getRequestContextPath();
-    if (ctxPath.length() > 0 && !s.startsWith(ctxPath))
+    if (containsContextPath(s) == -1)
     {
-      s = ctxPath + s;
+      s = getRequestContextPath() + s;
     }
     
     return s;
@@ -978,11 +977,10 @@ public class PortletExternalContextImpl
     }
     
     // Now remove up through the ContextPath as we don't want it
-    String ctxPath = getRequestContextPath();
-    int i = path.indexOf(ctxPath);
+    int i = containsContextPath(path);
     if (i != -1)
     {
-      path = path.substring(i + ctxPath.length());
+      path = path.substring(i + getRequestContextPath().length());
     }
     
     // Determine the viewId by inspecting the URL
@@ -2487,17 +2485,32 @@ public class PortletExternalContextImpl
 
     // otherwise see if the URL contains the ContextPath
 
-    // Simple test is that the url doesn't contain
-    // the CONTEXT_PATH -- though ultimately may want to test
-    // if we are on the same server
+    return containsContextPath(url) == -1;
+  }
+
+  // For use when testing whether a target contains the ContextPath or not
+
+  private int containsContextPath(String url)
+  {
+    // Make sure the
     String ctxPath = getRequestContextPath();
     int i = url.indexOf(ctxPath);
-    int j = url.indexOf("?");
-    if (i != -1 && (j == -1 || i < j))
+    int q = url.indexOf('?');
+
+    if (i != -1 && i < q)
     {
-      return false;
+      // make sure its actually the ContextPath and not the beginning of the target.
+      // I.e. avoid thinking /simple.jspx contains the context path when the CP is
+      // /simple
+
+      int l = ctxPath.length();
+      if (url.length() != i + l && url.charAt(i + l) != '/')
+      {
+        // Not a ContextPath
+        i = -1;
+      }
     }
-    return true;
+    return i;
   }
   
   private boolean isFacesURL(String url)