cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1042821 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/URITemplate.java test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Date Mon, 06 Dec 2010 22:31:23 GMT
Author: sergeyb
Date: Mon Dec  6 22:31:21 2010
New Revision: 1042821

URL: http://svn.apache.org/viewvc?rev=1042821&view=rev
Log:
[CXF-3168] : checking for spaces around template vars

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=1042821&r1=1042820&r2=1042821&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Mon Dec  6 22:31:21 2010
@@ -386,7 +386,7 @@ public final class URITemplate {
      * Variable of URITemplate. Variable has either "{varname:pattern}" syntax or "{varname}".
      */
     private static final class Variable extends UriChunk {
-        private static final Pattern VARIABLE_PATTERN = Pattern.compile("(\\w[-\\w\\.]*)(\\:(.+))?");
+        private static final Pattern VARIABLE_PATTERN = Pattern.compile("(\\w[-\\w\\.]*[
]*)(\\:(.+))?");
         private String name;
         private Pattern pattern;
 
@@ -402,12 +402,13 @@ public final class URITemplate {
                 throw new IllegalArgumentException("uriChunk is empty");
             }
             if (CurlyBraceTokenizer.insideBraces(uriChunk)) {
-                uriChunk = CurlyBraceTokenizer.stripBraces(uriChunk);
+                uriChunk = CurlyBraceTokenizer.stripBraces(uriChunk).trim();
                 Matcher matcher = VARIABLE_PATTERN.matcher(uriChunk);
                 if (matcher.matches()) {
                     name = matcher.group(1).trim();
                     if (matcher.group(2) != null && matcher.group(3) != null) {
-                        pattern = Pattern.compile(matcher.group(3).trim());
+                        String patternExpression = matcher.group(3).trim();
+                        pattern = Pattern.compile(patternExpression);
                     }
                     return;
                 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=1042821&r1=1042820&r2=1042821&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Mon Dec  6 22:31:21 2010
@@ -191,15 +191,30 @@ public class URITemplateTest extends Ass
 
     @Test
     public void testBasicCustomExpression() throws Exception {
-        URITemplate uriTemplate = new URITemplate("/books/{bookId:[^/]+?}");
+        doTestBasicCustomExpression("/books/{bookId:[^/]+?}");
+    }
+    
+    @Test
+    public void testBasicCustomExpressionWithSpaces() throws Exception {
+        doTestBasicCustomExpression("/books/{ bookId : [^/]+? }");
+    }
+    
+    @Test
+    public void testBasicCustomExpressionWithSpaces2() throws Exception {
+        doTestBasicCustomExpression("/books/{ bookId }/");
+    }
+    
+    private void doTestBasicCustomExpression(String expression) {
+        URITemplate uriTemplate = new URITemplate(expression);
         MultivaluedMap<String, String> values = new MetadataMap<String, String>();
 
         boolean match = uriTemplate.match("/books/123/chapter/1", values);
         assertTrue(match);
         assertEquals("123", values.getFirst("bookId"));
         String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
-        assertEquals("/chapter/1", subResourcePath);
+        assertEquals("/chapter/1", subResourcePath);    
     }
+    
 
     @Test
     public void testBasicCustomExpression2() throws Exception {



Mime
View raw message