cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6366] Encoding forward slashes for matrix parameters
Date Thu, 23 Apr 2015 11:25:21 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 06b934503 -> 5115833f4


[CXF-6366] Encoding forward slashes for matrix parameters


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5115833f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5115833f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5115833f

Branch: refs/heads/3.0.x-fixes
Commit: 5115833f4a65d801d4f493f1f2e3173b5d07b679
Parents: 06b9345
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Apr 23 12:23:20 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Apr 23 12:24:58 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/impl/UriBuilderImpl.java   | 23 +++++++++++++-------
 .../cxf/jaxrs/impl/UriBuilderImplTest.java      |  7 ++++++
 2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5115833f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
index 84065b1..ae10a1b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
@@ -689,9 +689,9 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
         }
         List<String> list = matrix.get(name);
         if (list == null) {
-            matrix.put(name, toStringList(values));
+            matrix.put(name, toStringList(true, values));
         } else {
-            list.addAll(toStringList(values));
+            list.addAll(toStringList(true, values));
         }
         return this;
     }
@@ -703,9 +703,9 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
         }
         List<String> list = query.get(name);
         if (list == null) {
-            query.put(name, toStringList(values));
+            query.put(name, toStringList(false, values));
         } else {
-            list.addAll(toStringList(values));
+            list.addAll(toStringList(false, values));
         }
         return this;
     }
@@ -723,7 +723,7 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
             throw new IllegalArgumentException("name is null");
         }
         if (values != null && values.length >= 1 && values[0] != null)
{
-            matrix.put(name, toStringList(values));
+            matrix.put(name, toStringList(true, values));
         } else {
             matrix.remove(name);
         }
@@ -779,7 +779,7 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
             throw new IllegalArgumentException("name is null");
         }
         if (values != null && values.length >= 1 && values[0] != null)
{
-            query.put(name, toStringList(values));
+            query.put(name, toStringList(false, values));
         } else {
             query.remove(name);
         }
@@ -805,7 +805,7 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
      * @return list of strings
      * @throws IllegalArgumentException when one of values is null
      */
-    private List<String> toStringList(Object... values) throws IllegalArgumentException
{
+    private List<String> toStringList(boolean encodeSlash, Object... values) throws
IllegalArgumentException {
         List<String> list = new ArrayList<String>();
         if (values != null) {
             for (int i = 0; i < values.length; i++) {
@@ -813,7 +813,11 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
                 if (value == null) {
                     throw new IllegalArgumentException("Null value on " + i + " position");
                 }
-                list.add(value.toString());
+                String strValue = value.toString();
+                if (encodeSlash) {
+                    strValue = strValue.replaceAll("/", "%2F");
+                }
+                list.add(strValue);
             }
         }
         if (list.isEmpty()) {
@@ -840,6 +844,9 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
                 boolean templateValue = val.startsWith("{") && val.endsWith("}");
                 if (!templateValue) { 
                     val = HttpUtils.encodePartiallyEncoded(val, isQuery);
+                    if (!isQuery) {
+                        val = val.replaceAll("/", "%2F");
+                    }
                 } else {
                     val = new URITemplate(val).encodeLiteralCharacters(isQuery);
                 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5115833f/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
index 3abe884..a9ec843 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
@@ -480,6 +480,13 @@ public class UriBuilderImplTest extends Assert {
     }
     
     @Test
+    public void testMatrixWithSlash() throws Exception {
+        URI uri = new URI("http://bar/foo");
+        URI newUri = new UriBuilderImpl(uri).matrixParam("q", "1/2").build();   
+        assertEquals("URI is not built correctly", "http://bar/foo;q=1%2F2", newUri.toString());
+    }
+    
+    @Test
     public void replaceMatrixParamWithEmptyPathTest() throws Exception {
         String name = "name";
         String expected = "http://localhost:8080;name=x;name=y;name=y%20x;name=x%25y;name=%20";


Mime
View raw message