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:15 UTC

svn commit: r1368313 - in /myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main: java/org/apache/myfaces/portlet/faces/bridge/ java/org/apache/myfaces/portlet/faces/context/ resources/META-INF/

Author: mfreedman
Date: Wed Aug  1 23:40:15 2012
New Revision: 1368313

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

Modified:
    myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
    myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
    myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
    myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/resources/META-INF/faces-config.xml

Modified: myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java?rev=1368313&r1=1368312&r2=1368313&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java (original)
+++ myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java Wed Aug  1 23:40:15 2012
@@ -1720,7 +1720,6 @@ public class BridgeImpl
         return;
       }
 
-
       // now see if this scope is in the Map
       Map<String, Object> scopeMap = requestScopeMap.get(scopeId);
       if (scopeMap == null)

Modified: myfaces/portlet-bridge/core/branches/trunk_2.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/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=1368313&r1=1368312&r2=1368313&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java (original)
+++ myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java Wed Aug  1 23:40:15 2012
@@ -816,12 +816,10 @@ 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;
@@ -880,11 +878,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
@@ -1932,12 +1929,11 @@ public class PortletExternalContextImpl
       url = url.substring(0, i);
     }
 
-    // Now remove up through the ContextPath
-    String ctxPath = getRequestContextPath();
-    i = url.indexOf(ctxPath);
+    // Now remove up through the ContextPath if it exists
+    i = containsContextPath(url);
     if (i != -1)
     {
-      url = url.substring(i + ctxPath.length());
+      url = url.substring(i + getRequestContextPath().length());
     }
 
     String viewId = null;
@@ -2218,14 +2214,31 @@ public class PortletExternalContextImpl
     // 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)

Modified: myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java?rev=1368313&r1=1368312&r2=1368313&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java (original)
+++ myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java Wed Aug  1 23:40:15 2012
@@ -352,7 +352,7 @@ public class PortletFacesContextImpl ext
           removeList.add(name);
         }
       }
-      
+
       // Postpone the remove until after the iteration as it causes a ConcurrentModificationException on some appServers (WebSphere)
       for(Iterator<String> iter = removeList.iterator(); iter.hasNext();)
       {

Modified: myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/resources/META-INF/faces-config.xml?rev=1368313&r1=1368312&r2=1368313&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/portlet-bridge/core/branches/trunk_2.0.x/impl/src/main/resources/META-INF/faces-config.xml Wed Aug  1 23:40:15 2012
@@ -45,7 +45,7 @@
         	<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.config.dispatch.DispatchResponseConfiguratorImpl.*</bridge:excluded-attribute>
         	<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.context.*</bridge:excluded-attribute>
 		<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.context.AdfFacesPhaseListener.*</bridge:excluded-attribute>
-		<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.context.FacesContxtFactoryImpl.*</bridge:excluded-attribute>
+		<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.context.FacesContextFactoryImpl.*</bridge:excluded-attribute>
         	<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.dispatch.*</bridge:excluded-attribute>
         	<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.renderkit.*</bridge:excluded-attribute>
         	<bridge:excluded-attribute>org.apache.myfaces.trinidadinternal.uinode.*</bridge:excluded-attribute>