Author: markt
Date: Mon Sep  9 12:47:31 2013
New Revision: 1521076

URL: http://svn.apache.org/r1521076
Log:
Update 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/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1521073,1521075

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1521076&r1=1521075&r2=1521076&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
 Mon Sep  9 12:47:31 2013
@@ -26,6 +26,7 @@ serverContainer.servletContextMismatch=A
 serverContainer.servletContextMissing=No ServletContext was specified
 
 uriTemplate.duplicateParameter=The parameter [{0}] appears more than once in 
the path which is not permitted
+uriTemplate.emptySegment=The path [{0}] contains one or more empty segments 
which are is not permitted
 uriTemplate.invalidPath=The path [{0}] is not valid.
 uriTemplate.invalidSegment=The segment [{0}] is not valid in the provided path 
[{1}]
 

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java?rev=1521076&r1=1521075&r2=1521076&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UriTemplate.java 
Mon Sep  9 12:47:31 2013
@@ -52,14 +52,24 @@ public class UriTemplate {
         StringBuilder normalized = new StringBuilder(path.length());
         Set<String> paramNames = new HashSet<String>();
 
-        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) {
-                continue;
+                if (i == 0) {
+                    // Ignore the first empty segment as the path must always
+                    // start with '/'
+                    continue;
+                } else {
+                    // As per EG discussion, all other empty segments are
+                    // invalid
+                    throw new IllegalArgumentException(sm.getString(
+                            "uriTemplate.emptySegment", path));
+                }
             }
             normalized.append('/');
             int index = -1;

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java?rev=1521076&r1=1521075&r2=1521076&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/server/TestUriTemplate.java
 Mon Sep  9 12:47:31 2013
@@ -169,4 +169,37 @@ public class TestUriTemplate {
         Assert.assertEquals("x", result.get("a"));
         Assert.assertEquals("x", result.get("b"));
     }
+
+
+    @Test(expected=java.lang.IllegalArgumentException.class)
+    public void testEgMailingList01() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var}");
+        @SuppressWarnings("unused")
+        Map<String,String> result = t.match(new UriTemplate("/a/b/"));
+    }
+
+
+    @Test(expected=java.lang.IllegalArgumentException.class)
+    public void testEgMailingList02() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var}");
+        @SuppressWarnings("unused")
+        Map<String,String> result = t.match(new UriTemplate("/a/"));
+    }
+
+
+    @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(expected=java.lang.IllegalArgumentException.class)
+    public void testEgMailingList04() throws Exception {
+        UriTemplate t = new UriTemplate("/a/{var1}/{var2}");
+        @SuppressWarnings("unused")
+        Map<String,String> result = t.match(new UriTemplate("/a//c"));
+    }
 }



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

Reply via email to