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-7287] Correct decoding of values containing commas
Date Mon, 20 Mar 2017 14:56:03 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes e51e27dd7 -> 55c72f225


[CXF-7287] Correct decoding of values containing commas


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

Branch: refs/heads/3.1.x-fixes
Commit: 55c72f2257e9afaacfcd9de8fe0635ea0de6d786
Parents: e51e27d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Mar 20 14:12:06 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Mar 20 14:55:47 2017 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java     | 5 +++++
 .../cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java | 9 +++++++++
 2 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/55c72f22/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
index abf6eef..4a1c3ef 100644
--- a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
+++ b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
@@ -243,6 +243,11 @@ public class JsonMapObjectReaderWriter {
         int commaIndex = json.indexOf(",", from);
         if (commaIndex == -1) {
             commaIndex = json.length();
+        } else if (json.charAt(commaIndex - 1) != '\"' && json.charAt(from) == '\"')
{
+            String value = json.substring(0, commaIndex).trim();
+            if (value.lastIndexOf("\"") != value.length() - 1) {
+                commaIndex = getCommaIndex(json, commaIndex + 1);
+            }
         }
         return commaIndex;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/55c72f22/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
b/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
index 54c63ae..d57e616 100644
--- a/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
+++ b/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
@@ -57,4 +57,13 @@ public class JsonMapObjectReaderWriterTest extends Assert {
         assertEquals(Collections.singletonList("cValue"), map.get("c"));
         assertNull(map.get("f"));
     }
+    @Test
+    public void testReadMapWithValueCommas() throws Exception {
+        String json = "{\"a\":\"aValue1,aValue2\",\"b\":\"bValue1\"\r\n,\"c\":[\"cValue1,
cValue2\"]}";
+        Map<String, Object> map = new JsonMapObjectReaderWriter().fromJson(json);
+        assertEquals(3, map.size());
+        assertEquals("aValue1,aValue2", map.get("a"));
+        assertEquals("bValue1", map.get("b"));
+        assertEquals(Collections.singletonList("cValue1, cValue2"), map.get("c"));
+    }
 }


Mime
View raw message