Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 5c05a87

Browse files
committed
Fix a potential crash in ApiSectionResponse
There is a case where a notebook can have no sections in it. Under these conditions the existing code would crash, as generating a new URL with a null string throws. So, checking to ensure that the property exists before generating the ULR fixes the problem. Also, there was some incorrect logic around the "links" node. The schema does not allow for the pagesUrl property, so the code as written will never work. Cleaning out that logic fixes things up.
1 parent 0cff1dc commit 5c05a87

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/com/microsoft/onenote/pickerlib/ApiSectionResponse.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ class ApiSectionResponse extends ApiResponse {
1616
private URL pagesUrl;
1717

1818
public ApiSectionResponse(JSONObject object) throws JSONException, MalformedURLException{
19-
super(object);
20-
JSONObject links = object.optJSONObject("links");
21-
setIsDefault(object.optBoolean("isDefault"));
22-
if (links != null) {
23-
setPagesUrl(new URL(links.getJSONObject("pagesUrl").getString("href")));
24-
} else {
25-
setPagesUrl(new URL(object.getString("pagesUrl")));
19+
super(object);
20+
21+
if (object != null) {
22+
setIsDefault(object.optBoolean("isDefault"));
23+
24+
if (object.has("pagesUrl")) {
25+
this.setPagesUrl(new URL(object.getString("pagesUrl")));
26+
}
2627
}
2728
}
2829

0 commit comments

Comments
 (0)