@@ -71,7 +71,7 @@ public void enterJson(JSONParser.JsonContext ctx) {
71
71
*/
72
72
@ Override
73
73
public void enterPair (JSONParser .PairContext ctx ) {
74
- String name = unquoteEmbeddedQuotes (StringUtils .stripQuotes (ctx .STRING ().getText ()));
74
+ String name = resolveEscapeSequences (StringUtils .stripQuotes (ctx .STRING ().getText ()));
75
75
currentPairName .push (name );
76
76
}
77
77
@@ -169,7 +169,7 @@ public void exitJsonArray(JSONParser.JsonArrayContext ctx) {
169
169
*/
170
170
@ Override
171
171
public void enterJsonString (JSONParser .JsonStringContext ctx ) {
172
- String cleanString = unquoteEmbeddedQuotes (StringUtils .stripQuotes (ctx .STRING ().getText ()));
172
+ String cleanString = resolveEscapeSequences (StringUtils .stripQuotes (ctx .STRING ().getText ()));
173
173
currentScalarValue = new PyString (cleanString );
174
174
currentValueType .push (ValueType .SCALAR );
175
175
}
@@ -347,10 +347,17 @@ private void addToArrayIfNeeded() {
347
347
}
348
348
}
349
349
350
- private static String unquoteEmbeddedQuotes (String text ) {
350
+ private static String resolveEscapeSequences (String text ) {
351
351
String result = text ;
352
352
if (!StringUtils .isEmpty (text )) {
353
353
result = text .replace ("\\ \" " , "\" " );
354
+ result = result .replace ("\\ \\ " , "\\ " );
355
+ result = result .replace ("\\ b" , "\b " );
356
+ result = result .replace ("\\ f" , "\f " );
357
+ result = result .replace ("\\ n" , "\n " );
358
+ result = result .replace ("\\ r" , "\r " );
359
+ result = result .replace ("\\ t" , "\t " );
360
+ result = result .replace ("\\ /" , "/" );
354
361
}
355
362
return result ;
356
363
}
0 commit comments