cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [2/2] cxf git commit: [CXF-7287] Making sure more values with more than 1 comma are correctly parsed
Date Mon, 20 Mar 2017 14:55:21 GMT
[CXF-7287] Making sure more values with more than 1 comma are correctly parsed


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

Branch: refs/heads/master
Commit: 6613e46662317ea151f72e26e5deb4f50148a148
Parents: c3d5841
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Mar 20 14:55:05 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Mar 20 14:55:05 2017 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java   | 10 +++++-----
 .../jaxrs/json/basic/JsonMapObjectReaderWriterTest.java   |  6 ++++--
 2 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6613e466/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 bc106e2..89d502d 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
@@ -190,7 +190,7 @@ public class JsonMapObjectReaderWriter {
                 values.put(name, internalFromJsonAsList(name, newJson));
                 i = closingIndex + 1;
             } else {
-                int commaIndex = getCommaIndex(json, sepIndex + j);
+                int commaIndex = getCommaIndex(json, sepIndex + j, sepIndex + j);
                 Object value = readPrimitiveValue(name, json, sepIndex + j, commaIndex);
                 values.put(name, value);
                 i = commaIndex + 1;
@@ -211,7 +211,7 @@ public class JsonMapObjectReaderWriter {
                 values.add(nextMap.map);
                 i = closingIndex + 1;
             } else {
-                int commaIndex = getCommaIndex(json, i);
+                int commaIndex = getCommaIndex(json, i, i);
                 Object value = readPrimitiveValue(name, json, i, commaIndex);
                 values.add(value);
                 i = commaIndex;
@@ -239,14 +239,14 @@ public class JsonMapObjectReaderWriter {
         return value;
     }
 
-    protected static int getCommaIndex(String json, int from) {
+    protected static int getCommaIndex(String json, int start, int from) {
         int commaIndex = json.indexOf(",", from);
         if (commaIndex == -1) {
             commaIndex = json.length();
-        } else if (json.charAt(commaIndex - 1) != '\"' && json.charAt(from) == '\"')
{
+        } else if (json.charAt(commaIndex - 1) != '\"' && json.charAt(start) == '\"')
{
             String value = json.substring(0, commaIndex).trim();
             if (value.lastIndexOf("\"") != value.length() - 1) {
-                commaIndex = getCommaIndex(json, commaIndex + 1);
+                commaIndex = getCommaIndex(json, start, commaIndex + 1);
             }
         }
         return commaIndex;

http://git-wip-us.apache.org/repos/asf/cxf/blob/6613e466/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 f56bab2..1500354 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
@@ -59,11 +59,13 @@ public class JsonMapObjectReaderWriterTest extends Assert {
     }
     @Test
     public void testReadMapWithValueCommas() throws Exception {
-        String json = "{\"a\":\"aValue1,aValue2\",\"b\":\"bValue1\"\r\n,\"c\":[\"cValue1,
cValue2\"]}";
+        String json = "{\"a\":\"aValue1,aValue2\",\"b\":\"bValue1\"\r\n,\"c\":[\"cValue1,
cValue2\"],"
+            + "\"d\":\"dValue1,dValue2,dValue3,dValue4\"}";
         Map<String, Object> map = new JsonMapObjectReaderWriter().fromJson(json);
-        assertEquals(3, map.size());
+        assertEquals(4, map.size());
         assertEquals("aValue1,aValue2", map.get("a"));
         assertEquals("bValue1", map.get("b"));
         assertEquals(Collections.singletonList("cValue1, cValue2"), map.get("c"));
+        assertEquals("dValue1,dValue2,dValue3,dValue4", map.get("d"));
     }
 }


Mime
View raw message