Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link in the description to the SonarQube issue you are fixing here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a reason, or revert this change. There does not appear to be an associated SonarQube issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that. The index is still being updated within the loop. Also, I have marked the issue as 'Accepted', so it does not need to be fixed. Please revert this change.

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