Revision: 1236
          http://stripes.svn.sourceforge.net/stripes/?rev=1236&view=rev
Author:   bengunter
Date:     2010-05-18 18:57:31 +0000 (Tue, 18 May 2010)

Log Message:
-----------
Fixed STS-731: Clean URLs with appended parameters does not work correctly. 
Changed UrlBindingFactory to ignore the literal suffix first and then trim any 
trailing slashes, as suggested by Alexander Suslov. Indeed, that is the correct 
order, and it fixes the problem.

Modified Paths:
--------------
    
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
    
branches/1.5.x/tests/src/net/sourceforge/stripes/controller/UrlBindingFactoryTests.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
===================================================================
--- 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
        2010-05-18 18:02:42 UTC (rev 1235)
+++ 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
        2010-05-18 18:57:31 UTC (rev 1236)
@@ -251,17 +251,17 @@
         if (prototype == null)
             return null;
 
-        // ignore trailing slashes in the URI
+        // check for literal suffix in prototype and ignore it if found
         int length = uri.length();
-        while (length > 0 && uri.charAt(length - 1) == '/')
-            --length;
-
-        // check for literal suffix in prototype and ignore it if found
         String suffix = prototype.getSuffix();
         if (suffix != null && uri.endsWith(suffix)) {
             length -= suffix.length();
         }
 
+        // ignore trailing slashes in the URI
+        while (length > 0 && uri.charAt(length - 1) == '/')
+            --length;
+
         // extract the request parameters and add to new binding object
         ArrayList<Object> components = new 
ArrayList<Object>(prototype.getComponents().size());
         int index = prototype.getPath().length();

Modified: 
branches/1.5.x/tests/src/net/sourceforge/stripes/controller/UrlBindingFactoryTests.java
===================================================================
--- 
branches/1.5.x/tests/src/net/sourceforge/stripes/controller/UrlBindingFactoryTests.java
     2010-05-18 18:02:42 UTC (rev 1235)
+++ 
branches/1.5.x/tests/src/net/sourceforge/stripes/controller/UrlBindingFactoryTests.java
     2010-05-18 18:57:31 UTC (rev 1236)
@@ -1,5 +1,9 @@
 package net.sourceforge.stripes.controller;
 
+import static java.lang.String.format;
+
+import java.util.List;
+
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.action.ActionBeanContext;
 import net.sourceforge.stripes.config.DontAutoLoad;
@@ -98,6 +102,13 @@
     public static class SuffixActionBean1 extends BaseActionBean {}
     @DontAutoLoad 
@net.sourceforge.stripes.action.UrlBinding("/suffix/{a}/{b}/{c}/{d}.action")
     public static class SuffixActionBean2 extends BaseActionBean {}
+
+    @DontAutoLoad @net.sourceforge.stripes.action.UrlBinding("/sts731/{a}/")
+    public static class STS731ActionBean1 extends BaseActionBean {}
+    @DontAutoLoad 
@net.sourceforge.stripes.action.UrlBinding("/sts731/{a}/foo/")
+    public static class STS731ActionBean2 extends BaseActionBean {}
+    @DontAutoLoad 
@net.sourceforge.stripes.action.UrlBinding("/sts731/{a}/bar/")
+    public static class STS731ActionBean3 extends BaseActionBean {}
     
     private static final Log log = 
Log.getInstance(UrlBindingFactoryTests.class);
     private static UrlBindingFactory urlBindingFactory;
@@ -110,7 +121,9 @@
                 FooActionBean.class, FooActionBean1.class, 
FooActionBean2.class,
                 FooActionBean3.class, FooActionBean4.class, 
FooActionBean5.class,
                 FooActionBean6.class, FooActionBean7.class, 
FooActionBean8.class,
-                SuffixActionBean1.class, SuffixActionBean2.class };
+                SuffixActionBean1.class, SuffixActionBean2.class,
+                STS731ActionBean1.class, STS731ActionBean2.class, 
STS731ActionBean3.class
+        };
 
         UrlBindingFactory factory = new UrlBindingFactory();
         for (Class<? extends ActionBean> clazz : classes) {
@@ -121,11 +134,12 @@
         urlBindingFactory = factory;
     }
 
-    private void checkBinding(String uri, Class<? extends ActionBean> 
expected) {
+    private List<UrlBindingParameter> checkBinding(String uri, Class<? extends 
ActionBean> expected) {
         log.debug("Checking that ", uri, " maps to ", expected);
         UrlBinding binding = urlBindingFactory.getBinding(uri);
-        Assert.assertNotNull(binding);
+        Assert.assertNotNull(binding, "The uri \"" + uri + "\" matched 
nothing");
         Assert.assertSame(binding.getBeanType(), expected);
+        return binding.getParameters();
     }
 
     @Test(groups = "fast")
@@ -250,6 +264,17 @@
         checkBinding("/foo/goo/1", FooActionBean8.class);
         checkBinding("/foo/goo/1/", FooActionBean8.class);
         checkBinding("/foo/goo/1/2", FooActionBean8.class);
+
+        // Suffixes, as reported in STS-731
+        for (String value : new String[] { "really-long", "long", "XX", "X" }) 
{
+            List<UrlBindingParameter> param;
+            param = checkBinding(format("/sts731/%s/", value), 
STS731ActionBean1.class);
+            Assert.assertEquals(param.get(0).getValue(), value);
+            param = checkBinding(format("/sts731/%s/foo/", value), 
STS731ActionBean2.class);
+            Assert.assertEquals(param.get(0).getValue(), value);
+            param = checkBinding(format("/sts731/%s/bar/", value), 
STS731ActionBean3.class);
+            Assert.assertEquals(param.get(0).getValue(), value);
+        }
     }
 
     @Test(groups = "fast")


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------

_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to