Commit 4e3d0f5b authored by Stephane Nicoll's avatar Stephane Nicoll

Fix parsing of value with comma

Closes gh-12297
parent c2f7dd86
......@@ -124,6 +124,7 @@ public class BasicJsonParser implements JsonParser {
int index = 0;
int inObject = 0;
int inList = 0;
boolean inValue = false;
StringBuilder build = new StringBuilder();
while (index < json.length()) {
char current = json.charAt(index);
......@@ -139,7 +140,10 @@ public class BasicJsonParser implements JsonParser {
if (current == ']') {
inList--;
}
if (current == ',' && inObject == 0 && inList == 0) {
if (current == '"') {
inValue = !inValue;
}
if (current == ',' && inObject == 0 && inList == 0 && !inValue) {
list.add(build.toString());
build.setLength(0);
}
......
......@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Dave Syer
* @author Jean de Klerk
* @author Stephane Nicoll
*/
public abstract class AbstractJsonParserTests {
......@@ -63,6 +64,13 @@ public abstract class AbstractJsonParserTests {
assertThat(map.get("foo")).isEqualTo("123");
}
@Test
public void stringContainingComma() {
Map<String, Object> map = this.parser.parseMap("{\"foo\":\"bar1,bar2\"}");
assertThat(map).hasSize(1);
assertThat(map.get("foo")).isEqualTo("bar1,bar2");
}
@Test
public void emptyMap() {
Map<String, Object> map = this.parser.parseMap("{}");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment