Author: markt Date: Mon Sep 9 20:10:04 2013 New Revision: 1521271 URL: http://svn.apache.org/r1521271 Log: UriTemplate should not trigger failures for '/' for for instances used for matching that end in '/'
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=1521271&r1=1521270&r2=1521271&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 20:10:04 2013 @@ -60,9 +60,11 @@ public class UriTemplate { for (int i = 0; i < segments.length; i++) { String segment = segments[i]; if (segment.length() == 0) { - if (i == 0) { + if (i == 0 || (i == segments.length - 1 && paramCount == 0)) { // Ignore the first empty segment as the path must always // start with '/' + // Ending with a '/' is also OK for instances used for + // matches but not for parameterised templates. continue; } else { // As per EG discussion, all other empty segments are 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=1521271&r1=1521270&r2=1521271&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 20:10:04 2013 @@ -171,19 +171,19 @@ public class TestUriTemplate { } - @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(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.assertNull(result); } @@ -202,4 +202,12 @@ public class TestUriTemplate { @SuppressWarnings("unused") Map<String,String> result = t.match(new UriTemplate("/a//c")); } + + + @Test(expected=java.lang.IllegalArgumentException.class) + public void testEgMailingList05() throws Exception { + UriTemplate t = new UriTemplate("/a/{var}/"); + @SuppressWarnings("unused") + Map<String,String> result = t.match(new UriTemplate("/a/b/")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org