mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #14521 from DevOrc:fixes-14348
* pr/14521: Support escaped characters in BasicJsonParser
This commit is contained in:
commit
ccbbe0f0f3
@ -125,9 +125,16 @@ public class BasicJsonParser implements JsonParser {
|
|||||||
int inObject = 0;
|
int inObject = 0;
|
||||||
int inList = 0;
|
int inList = 0;
|
||||||
boolean inValue = false;
|
boolean inValue = false;
|
||||||
|
boolean inEscape = false;
|
||||||
StringBuilder build = new StringBuilder();
|
StringBuilder build = new StringBuilder();
|
||||||
while (index < json.length()) {
|
while (index < json.length()) {
|
||||||
char current = json.charAt(index);
|
char current = json.charAt(index);
|
||||||
|
if (inEscape) {
|
||||||
|
build.append(current);
|
||||||
|
index++;
|
||||||
|
inEscape = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (current == '{') {
|
if (current == '{') {
|
||||||
inObject++;
|
inObject++;
|
||||||
}
|
}
|
||||||
@ -147,6 +154,9 @@ public class BasicJsonParser implements JsonParser {
|
|||||||
list.add(build.toString());
|
list.add(build.toString());
|
||||||
build.setLength(0);
|
build.setLength(0);
|
||||||
}
|
}
|
||||||
|
else if (current == '\\') {
|
||||||
|
inEscape = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
build.append(current);
|
build.append(current);
|
||||||
}
|
}
|
||||||
|
@ -170,4 +170,11 @@ public abstract class AbstractJsonParserTests {
|
|||||||
this.parser.parseList("\n\t{}");
|
this.parser.parseList("\n\t{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void escapeQuote() {
|
||||||
|
String input = "{\"foo\": \"\\\"bar\\\"\"}";
|
||||||
|
Map<String, Object> map = this.parser.parseMap(input);
|
||||||
|
assertThat(map.get("foo")).isEqualTo("\"bar\"");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user