@@ -141,7 +141,7 @@ public static String escape(String string) {
141
141
if (mustEscape (cp )) {
142
142
sb .append ("&#x" );
143
143
sb .append (Integer .toHexString (cp ));
144
- sb .append (";" );
144
+ sb .append (';' );
145
145
} else {
146
146
sb .appendCodePoint (cp );
147
147
}
@@ -191,31 +191,7 @@ public static String unescape(String string) {
191
191
final int semic = string .indexOf (';' , i );
192
192
if (semic > i ) {
193
193
final String entity = string .substring (i + 1 , semic );
194
- if (entity .charAt (0 ) == '#' ) {
195
- int cp ;
196
- if (entity .charAt (1 ) == 'x' ) {
197
- // hex encoded unicode
198
- cp = Integer .parseInt (entity .substring (2 ), 16 );
199
- } else {
200
- // decimal encoded unicode
201
- cp = Integer .parseInt (entity .substring (1 ));
202
- }
203
- sb .appendCodePoint (cp );
204
- } else {
205
- if ("quot" .equalsIgnoreCase (entity )) {
206
- sb .append ('"' );
207
- } else if ("amp" .equalsIgnoreCase (entity )) {
208
- sb .append ('&' );
209
- } else if ("apos" .equalsIgnoreCase (entity )) {
210
- sb .append ('\'' );
211
- } else if ("lt" .equalsIgnoreCase (entity )) {
212
- sb .append ('<' );
213
- } else if ("gt" .equalsIgnoreCase (entity )) {
214
- sb .append ('>' );
215
- } else {// unsupported xml entity. leave encoded
216
- sb .append ('&' ).append (entity ).append (';' );
217
- }
218
- }
194
+ sb .append (XMLTokener .unescapeEntity (entity ));
219
195
// skip past the entity we just parsed.
220
196
i += entity .length () + 1 ;
221
197
} else {
@@ -364,7 +340,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
364
340
throw x .syntaxError ("Missing value" );
365
341
}
366
342
jsonobject .accumulate (string ,
367
- keepStrings ? unescape ((String )token ) : stringToValue ((String ) token ));
343
+ keepStrings ? ((String )token ) : stringToValue ((String ) token ));
368
344
token = null ;
369
345
} else {
370
346
jsonobject .accumulate (string , "" );
@@ -396,7 +372,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
396
372
string = (String ) token ;
397
373
if (string .length () > 0 ) {
398
374
jsonobject .accumulate ("content" ,
399
- keepStrings ? unescape ( string ) : stringToValue (string ));
375
+ keepStrings ? string : stringToValue (string ));
400
376
}
401
377
402
378
} else if (token == LT ) {
@@ -430,11 +406,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
430
406
* @return JSON value of this string or the string
431
407
*/
432
408
public static Object stringToValue (String string ) {
433
- Object ret = JSONObject .stringToValue (string );
434
- if (ret instanceof String ){
435
- return unescape ((String )ret );
436
- }
437
- return ret ;
409
+ return JSONObject .stringToValue (string );
438
410
}
439
411
440
412
/**
0 commit comments