Author: markt
Date: Mon Sep  9 12:32:16 2013
New Revision: 1521073

URL: http://svn.apache.org/r1521073
Log:
Add some tests based on the WS EG discussions around some edge cases. Note that 
some of these will never happen in practise as Tomcat will have normalized the 
URI.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java
    tomcat/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java?rev=1521073&r1=1521072&r2=1521073&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java Mon 
Sep  9 12:32:16 2013
@@ -52,13 +52,16 @@ public class UriTemplate {
         StringBuilder normalized = new StringBuilder(path.length());
         Set<String> paramNames = new HashSet<>();
 
-        String[] segments = path.split("/");
+        // Include empty segments.
+        String[] segments = path.split("/", -1);
         int paramCount = 0;
         int segmentCount = 0;
 
         for (int i = 0; i < segments.length; i++) {
             String segment = segments[i];
-            if (segment.length() == 0) {
+            // Ignore the first empty segment as the path must always start
+            // with '/'
+            if (i == 0 && segment.length() == 0) {
                 continue;
             }
             normalized.append('/');

Modified: 
tomcat/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java?rev=1521073&r1=1521072&r2=1521073&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java 
Mon Sep  9 12:32:16 2013
@@ -169,4 +169,43 @@ public class TestUriTemplate {
         Assert.assertEquals("x", result.get("a"));
         Assert.assertEquals("x", result.get("b"));
     }
+
+
+    @Test
+    public void testEgMailingList01() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var}");
+        Map<String,String> result = t.match(new UriTemplate("/a/b/"));
+
+        Assert.assertNull(result);
+    }
+
+
+    @Test
+    public void testEgMailingList02() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var}");
+        Map<String,String> result = t.match(new UriTemplate("/a/"));
+
+        Assert.assertEquals(1, result.size());
+        Assert.assertEquals("", result.get("var"));
+    }
+
+
+    @Test
+    public void testEgMailingList03() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var}");
+        Map<String,String> result = t.match(new UriTemplate("/a"));
+
+        Assert.assertNull(result);
+    }
+
+
+    @Test
+    public void testEgMailingList04() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var1}/{var2}");
+        Map<String,String> result = t.match(new UriTemplate("/a//c"));
+
+        Assert.assertEquals(2, result.size());
+        Assert.assertEquals("", result.get("var1"));
+        Assert.assertEquals("c", result.get("var2"));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to