Merge branch '1.5.x'

This commit is contained in:
Stephane Nicoll 2018-03-01 17:26:51 +01:00
commit ef9fb1696c
2 changed files with 13 additions and 1 deletions

View File

@ -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);
}

View File

@ -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("{}");