Skip to content

Commit bc8ea6d

Browse files
nchevobbervandermeulen
authored andcommitted
Bug 1968257 - [devtools] Fix Netmonitor response panel crash on null JSON response. a=RyanVM
Original Revision: https://phabricator.services.mozilla.com/D251555 Differential Revision: https://phabricator.services.mozilla.com/D252033
1 parent 31a3ea2 commit bc8ea6d

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

devtools/client/netmonitor/src/utils/request-utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,12 @@ function parseJSON(payloadUnclean) {
736736
if (
737737
!error &&
738738
(typeof json !== "object" ||
739+
json === null ||
739740
// Parsed JSON numbers might be different than the source, for example
740741
// JSON.parse("1516340399466235648") returns 1516340399466235600. In such case,
741742
// parseJsonLossless will return an object with `type: JSON_NUMBER` property.
742743
// We still want to display those numbers as the other numbers here.
743-
json.type === lazy.JSON_NUMBER)
744+
json?.type === lazy.JSON_NUMBER)
744745
) {
745746
return {};
746747
}

devtools/client/netmonitor/test/browser_net_json-null.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_task(async function () {
1414
info("Starting test... ");
1515

1616
const { document, store, windowRequire } = monitor.panelWin;
17-
const { L10N } = windowRequire("devtools/client/netmonitor/src/utils/l10n");
1817
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
1918

2019
store.dispatch(Actions.batchEnable(false));
@@ -112,3 +111,37 @@ add_task(async function () {
112111
);
113112
}
114113
});
114+
115+
add_task(async function () {
116+
const { tab, monitor } = await initNetMonitor(
117+
JSON_BASIC_URL + "?name=root-null",
118+
{
119+
requestCount: 1,
120+
}
121+
);
122+
info("Starting test... ");
123+
124+
const { document, store, windowRequire } = monitor.panelWin;
125+
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
126+
127+
store.dispatch(Actions.batchEnable(false));
128+
129+
// Execute requests.
130+
await performRequests(monitor, tab, 1);
131+
132+
const onCodeMirrorReady = waitForDOM(
133+
document,
134+
"#response-panel .CodeMirror-code"
135+
);
136+
137+
store.dispatch(Actions.toggleNetworkDetails());
138+
clickOnSidebarTab(document, "response");
139+
const [codeMirrorCodeEl] = await onCodeMirrorReady;
140+
is(
141+
codeMirrorCodeEl.querySelector("pre.CodeMirror-line span").textContent,
142+
"null",
143+
"root null JSON object is displayed in a CodeMirror editor"
144+
);
145+
146+
await teardown(monitor);
147+
});

devtools/client/netmonitor/test/sjs_json-test-server.sjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function handleRequest(request, response) {
1818
case "null":
1919
response.write('{ "greeting": null }');
2020
break;
21+
case "root-null":
22+
response.write(`null`);
23+
break;
2124
case "nogrip":
2225
response.write('{"obj": {"type": "string" }}');
2326
break;

0 commit comments

Comments
 (0)