Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/main/java/org/json/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Cookie {
/**
* Constructs a new Cookie object.
*/
public Cookie() {
private Cookie() {
}

/**
Expand Down Expand Up @@ -189,21 +189,30 @@ public static String toString(JSONObject jo) throws JSONException {
* @return The unescaped string.
*/
public static String unescape(String string) {
int i = 0;
int length = string.length();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; ++i) {

while (i < length) {
char c = string.charAt(i);
if (c == '+') {
c = ' ';
sb.append(' ');
i++;
} else if (c == '%' && i + 2 < length) {
int d = JSONTokener.dehexchar(string.charAt(i + 1));
int e = JSONTokener.dehexchar(string.charAt(i + 2));

if (d >= 0 && e >= 0) {
c = (char)(d * 16 + e);
i += 2;
sb.append((char)(d * 16 + e));
i += 3;
} else {
sb.append(c);
i++;
}
} else {
sb.append(c);
i++;
}
sb.append(c);
}
return sb.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/json/CookieList.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CookieList {
/**
* Constructs a new CookieList object.
*/
public CookieList() {
private CookieList() {
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/org/json/JSONML.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public class JSONML {
/**
* Constructs a new JSONML object.
*/
public JSONML() {
private JSONML() {
}


/**
* Parse XML values and store them in a JSONArray.
* @param x The XMLTokener containing the source string.
Expand Down Expand Up @@ -239,9 +240,21 @@ private static Object parse(
}
} else {
if (ja != null) {
ja.put(token instanceof String
? (config.isKeepStrings() ? XML.unescape((String)token) : XML.stringToValue((String)token))
: token);
Object value;

if (token instanceof String) {
String strToken = (String) token;
if (config.isKeepStrings()) {
value = XML.unescape(strToken);
} else {
value = XML.stringToValue(strToken);
}
} else {
value = token;
}

ja.put(value);

}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,25 +454,28 @@ public String nextTo(String delimiters) throws JSONException {
*/
public Object nextValue() throws JSONException {
char c = this.nextClean();
switch (c) {
case '{':

if (c == '{') {
this.back();
try {
return new JSONObject(this, jsonParserConfiguration);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
case '[':

} else if (c == '[') {
this.back();
try {
return new JSONArray(this, jsonParserConfiguration);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
}

return nextSimpleValue(c);
}


Object nextSimpleValue(char c) {
String string;

Expand All @@ -482,9 +485,8 @@ Object nextSimpleValue(char c) {
c == '\'') {
throw this.syntaxError("Strict mode error: Single quoted strings are not allowed");
}
switch (c) {
case '"':
case '\'':

if (c == '"' || c == '\'') {
return this.nextString(c);
}

Expand Down