@@ -141,7 +141,7 @@ public static String escape(String string) {
141141 if (mustEscape (cp )) {
142142 sb .append ("&#x" );
143143 sb .append (Integer .toHexString (cp ));
144- sb .append (";" );
144+ sb .append (';' );
145145 } else {
146146 sb .appendCodePoint (cp );
147147 }
@@ -191,31 +191,7 @@ public static String unescape(String string) {
191191 final int semic = string .indexOf (';' , i );
192192 if (semic > i ) {
193193 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 ));
219195 // skip past the entity we just parsed.
220196 i += entity .length () + 1 ;
221197 } else {
@@ -364,7 +340,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
364340 throw x .syntaxError ("Missing value" );
365341 }
366342 jsonobject .accumulate (string ,
367- keepStrings ? unescape ((String )token ) : stringToValue ((String ) token ));
343+ keepStrings ? ((String )token ) : stringToValue ((String ) token ));
368344 token = null ;
369345 } else {
370346 jsonobject .accumulate (string , "" );
@@ -396,7 +372,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
396372 string = (String ) token ;
397373 if (string .length () > 0 ) {
398374 jsonobject .accumulate ("content" ,
399- keepStrings ? unescape ( string ) : stringToValue (string ));
375+ keepStrings ? string : stringToValue (string ));
400376 }
401377
402378 } else if (token == LT ) {
@@ -430,11 +406,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, bool
430406 * @return JSON value of this string or the string
431407 */
432408 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 );
438410 }
439411
440412 /**
0 commit comments