Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0BB1C18B98 for ; Thu, 23 Apr 2015 11:23:43 +0000 (UTC) Received: (qmail 47594 invoked by uid 500); 23 Apr 2015 11:23:43 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 47533 invoked by uid 500); 23 Apr 2015 11:23:42 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 47524 invoked by uid 99); 23 Apr 2015 11:23:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 11:23:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C09EEDFDC3; Thu, 23 Apr 2015 11:23:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <811f6114968a4465b0a76f51d9613576@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6366] Encoding forward slashes for matrix parameters Date: Thu, 23 Apr 2015 11:23:42 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 982bdbc9d -> 78a46c1b0 [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/78a46c1b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/78a46c1b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/78a46c1b Branch: refs/heads/master Commit: 78a46c1b0284c2f074385c0932801a149fd0d591 Parents: 982bdbc Author: Sergey Beryozkin Authored: Thu Apr 23 12:23:20 2015 +0100 Committer: Sergey Beryozkin Committed: Thu Apr 23 12:23:20 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/78a46c1b/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 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 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 toStringList(Object... values) throws IllegalArgumentException { + private List toStringList(boolean encodeSlash, Object... values) throws IllegalArgumentException { List list = new ArrayList(); 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/78a46c1b/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";