You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/08/24 11:58:27 UTC
svn commit: r988457 - in /myfaces/shared/trunk/core/src:
main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java
Author: jakobk
Date: Tue Aug 24 09:58:27 2010
New Revision: 988457
URL: http://svn.apache.org/viewvc?rev=988457&view=rev
Log:
MYFACES-2891 Empty url mapping prefix causes infinite loop in DefaultViewHandlerSupport.handlePrefixMapping
Modified:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java?rev=988457&r1=988456&r2=988457&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java Tue Aug 24 09:58:27 2010
@@ -294,21 +294,43 @@ public class DefaultViewHandlerSupport i
*/
protected String handlePrefixMapping(String viewId, String prefix)
{
- /* If prefix mapping (such as "/faces/*") is used for FacesServlet, normalize the viewId according to the following
- algorithm, or its semantic equivalent, and return it.
+ // If prefix mapping (such as "/faces/*") is used for FacesServlet,
+ // normalize the viewId according to the following
+ // algorithm, or its semantic equivalent, and return it.
- Remove any number of occurrences of the prefix mapping from the viewId. For example, if the incoming value
- was /faces/faces/faces/view.xhtml the result would be simply view.xhtml.
- */
+ // Remove any number of occurrences of the prefix mapping from the viewId.
+ // For example, if the incoming value was /faces/faces/faces/view.xhtml
+ // the result would be simply view.xhtml.
+
+ if ("".equals(prefix))
+ {
+ // if prefix is an empty string (Spring environment), we let it be "//"
+ // in order to prevent an infinite loop in uri.startsWith(-emptyString-).
+ // Furthermore a prefix of "//" is just another double slash prevention.
+ prefix = "//";
+ }
+ else
+ {
+ // need to make sure its really /faces/* and not /facesPage.xhtml
+ prefix = prefix + '/';
+ }
+
String uri = viewId;
- prefix = prefix + '/'; //need to make sure its really /faces/* and not /facesPage.xhtml
while (uri.startsWith(prefix) || uri.startsWith("//"))
{
- if(uri.startsWith(prefix))
- uri = uri.substring(prefix.length() - 1); //cut off only /faces, leave the trailing '/' char for the next iteration
- else //uri starts with '//'
- uri = uri.substring(1); //cut off the leading slash, leaving the second slash to compare for the next iteration
+ if (uri.startsWith(prefix))
+ {
+ // cut off only /faces, leave the trailing '/' char for the next iteration
+ uri = uri.substring(prefix.length() - 1);
+ }
+ else
+ {
+ // uri starts with '//' --> cut off the leading slash, leaving
+ // the second slash to compare for the next iteration
+ uri = uri.substring(1);
+ }
}
+
//now delete any remaining leading '/'
// TODO: CJH: I don't think this is correct, considering that getActionURL() expects everything to
// start with '/', and in the suffix case we only mess with the suffix and leave leading
Modified: myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java?rev=988457&r1=988456&r2=988457&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java (original)
+++ myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupportTest.java Tue Aug 24 09:58:27 2010
@@ -140,4 +140,38 @@ public class DefaultViewHandlerSupportTe
Assert.assertNull(derivedViewId);
}
+
+ /**
+ * An empty prefix mapping can occur in Spring environments.
+ * @throws Exception
+ */
+ @Test
+ public void testEmptyPrefixMapping() throws Exception
+ {
+ DefaultViewHandlerSupport support = new DefaultViewHandlerSupport();
+
+ request.setPathElements("/testwebapp", "", "/view2.xhtml" , null);
+
+ String derivedViewId = support.calculateAndCheckViewId(facesContext, "/view2.xhtml");
+
+ Assert.assertEquals("/view2.xhtml", derivedViewId);
+ }
+
+ /**
+ * An empty prefix mapping can occur in Spring environments.
+ * However this should not only return the viewId, but also remove any
+ * leading double slashes.
+ * @throws Exception
+ */
+ @Test
+ public void testEmptyPrefixMappingDoubleSlash() throws Exception
+ {
+ DefaultViewHandlerSupport support = new DefaultViewHandlerSupport();
+
+ request.setPathElements("/testwebapp", "", "//view2.xhtml" , null);
+
+ String derivedViewId = support.calculateAndCheckViewId(facesContext, "//view2.xhtml");
+
+ Assert.assertEquals("/view2.xhtml", derivedViewId);
+ }
}