Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ std::optional<std::string> InspectorIoDelegate::GetTargetSessionId(
std::string_view view(message.data(), message.size());
std::unique_ptr<protocol::DictionaryValue> value =
protocol::DictionaryValue::cast(JsonUtil::parseJSON(view));
if (!value) {
return std::nullopt;
}
protocol::String target_session_id;
protocol::Value* target_session_id_value = value->get("sessionId");
if (target_session_id_value) {
Expand Down
39 changes: 39 additions & 0 deletions test/parallel/test-inspector-invalid-protocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
const common = require('../common');
const { spawn } = require('node:child_process');
const assert = require('node:assert');

(async () => {
const child = spawn(
process.execPath,
['--inspect-wait=0', '-e', "console.log('test');"],
{}
);

const url = await new Promise((resolve) => {
child.stderr.on('data', (data) => {
const msg = data.toString();
const match = msg.match(/ws:\/\/127\.0\.0\.1:(\d+)\/([a-f0-9-]+)/);
if (match) {
child.stderr.removeAllListeners('data');
return resolve(match[0]);
}
});
});

child.once('exit', (_, signal) => {
assert.strictEqual(signal, 'SIGTERM');
});

const socket = new WebSocket(url);

socket.addEventListener('open', common.mustCall(() => {
socket.send('This is not a valid protocol message');
}));

socket.addEventListener('message', common.mustCall((event) => {
assert.ok(Object.keys(JSON.parse(event.data)).includes('error'));
socket.close();
child.kill();
}));
})().then(common.mustCall());

Check failure on line 39 in test/parallel/test-inspector-invalid-protocol.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stdout --- Mismatched noop function calls. Expected exactly 1, actual 0. at Proxy.mustCall (/Users/runner/work/node/node/test/common/index.js:434:10) at Object.<anonymous> (/Users/runner/work/node/node/test/parallel/test-inspector-invalid-protocol.js:39:18) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1892:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/test/parallel/test-inspector-invalid-protocol.js

Check failure on line 39 in test/parallel/test-inspector-invalid-protocol.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stdout --- Mismatched noop function calls. Expected exactly 1, actual 0. at Proxy.mustCall (/Users/runner/work/node/node/test/common/index.js:434:10) at Object.<anonymous> (/Users/runner/work/node/node/test/parallel/test-inspector-invalid-protocol.js:39:18) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1892:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/test/parallel/test-inspector-invalid-protocol.js
Loading