File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -189,21 +189,30 @@ public static String toString(JSONObject jo) throws JSONException {
189189 * @return The unescaped string.
190190 */
191191 public static String unescape (String string ) {
192+ int i = 0 ;
192193 int length = string .length ();
193194 StringBuilder sb = new StringBuilder (length );
194- for (int i = 0 ; i < length ; ++i ) {
195+
196+ while (i < length ) {
195197 char c = string .charAt (i );
196198 if (c == '+' ) {
197- c = ' ' ;
199+ sb .append (' ' );
200+ i ++;
198201 } else if (c == '%' && i + 2 < length ) {
199202 int d = JSONTokener .dehexchar (string .charAt (i + 1 ));
200203 int e = JSONTokener .dehexchar (string .charAt (i + 2 ));
204+
201205 if (d >= 0 && e >= 0 ) {
202- c = (char )(d * 16 + e );
203- i += 2 ;
206+ sb .append ((char )(d * 16 + e ));
207+ i += 3 ;
208+ } else {
209+ sb .append (c );
210+ i ++;
204211 }
212+ } else {
213+ sb .append (c );
214+ i ++;
205215 }
206- sb .append (c );
207216 }
208217 return sb .toString ();
209218 }
You can’t perform that action at this time.
0 commit comments