Author: markt Date: Mon Sep 9 12:41:10 2013 New Revision: 1521075 URL: http://svn.apache.org/r1521075 Log: And now update after I find the later discussion about empty segments not being permitted (which is good since Tomcat will have normalized them out anyway)
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties 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/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1521075&r1=1521074&r2=1521075&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties Mon Sep 9 12:41:10 2013 @@ -24,6 +24,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/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=1521075&r1=1521074&r2=1521075&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:41:10 2013 @@ -59,10 +59,17 @@ public class UriTemplate { for (int i = 0; i < segments.length; i++) { String segment = segments[i]; - // Ignore the first empty segment as the path must always start - // with '/' - if (i == 0 && segment.length() == 0) { - continue; + if (segment.length() == 0) { + 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/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=1521075&r1=1521074&r2=1521075&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:41:10 2013 @@ -171,22 +171,19 @@ public class TestUriTemplate { } - @Test + @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/")); - - Assert.assertNull(result); } - @Test + @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/")); - - Assert.assertEquals(1, result.size()); - Assert.assertEquals("", result.get("var")); } @@ -199,13 +196,10 @@ public class TestUriTemplate { } - @Test + @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")); - - 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