Skip to content
Open
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
2 changes: 1 addition & 1 deletion test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class InspectorSession {
this._scriptsIdsByUrl.set(scriptId, url);
const fileUrl = url.startsWith('file:') ?
url : pathToFileURL(url).toString();
if (fileUrl === this.scriptURL().toString()) {
if (decodeURIComponent(fileUrl) === decodeURIComponent(this.scriptURL().toString())) {
this.mainScriptId = scriptId;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-inspector-async-context-brk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');
Expand Down Expand Up @@ -35,7 +35,7 @@
await new Promise((resolve, reject) => {
session.post('Debugger.setBreakpointByUrl', {
'lineNumber': 22,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'url': decodeURIComponent(pathToFileURL(path.resolve(__dirname, __filename)).toString()),
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct. The field url has to be a string in correct URL format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree - I totally failed to fix this. I spent hours on this trying to find the root cause, no success.
My plan is to ignore that bug :(

Copy link
Member

@cola119 cola119 Oct 30, 2025

Choose a reason for hiding this comment

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

@legendecas It seems that the inspector server can't resolve the file and fails to set breakpoints when the url has encoded values. Decoding the url by the client looks a valid workaround to me. What do you think?

Decoded URL

[inspector received] {"id":3,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":18,"url":"file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread~.js","columnNumber":0,"condition":""}}
[inspector send] {"id":3,"result":{"breakpointId":"1:18:0:file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread~.js","locations":[{"scriptId":"76","lineNumber":18,"columnNumber":8}]}}

Encoded URL

[inspector received] {"id":3,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":18,"url":"file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread%7E.js","columnNumber":0,"condition":""}}
[inspector send] {"id":3,"result":{"breakpointId":"1:18:0:file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread%7E.js","locations":[]}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that there is already logic implemented to percent-encode special characters.
It's even tested by one of node's CI.
However, it fails for ~ (and + maybe), and this PR means nothing until it understands why.

Copy link
Member

Choose a reason for hiding this comment

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

Note that there is already logic implemented to percent-encode special characters.

Can you point it out?

Copy link
Contributor Author

@kapouer kapouer Oct 30, 2025

Choose a reason for hiding this comment

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

No ! I only know there is a test about it, and that test doesn't include ~ + chars

- name: Re-run test in a folder whose name contains unusual chars
run: |
mv node "$DIR"
cd "$DIR"
./tools/test.py --flaky-tests keep_retrying -p actions -j 4
env:
DIR: dir%20with $unusual"chars?'åß∂ƒ©∆¬…`

Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting point. The filename including ? can work fine.

[inspector received] {"id":3,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":18,"url":"file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread%3F.js","columnNumber":0,"condition":""}}
[inspector send] {"id":3,"result":{"breakpointId":"1:18:0:file:///Users/kohei/Documents/node/test/parallel/test-inspector-connect-main-thread%3F.js","locations":[{"scriptId":"76","lineNumber":18,"columnNumber":8}]}}

'columnNumber': 0,
'condition': ''
}, (error, result) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-inspector-bindings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
Expand Down Expand Up @@ -86,7 +86,7 @@
session.post('Debugger.enable', () => cbAsSecondArgCalled = true);
session.post('Debugger.setBreakpointByUrl', {
'lineNumber': 13,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'url': decodeURIComponent(pathToFileURL(path.resolve(__dirname, __filename)).toString()),
'columnNumber': 0,
'condition': ''
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-inspector-multisession-js.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
const common = require('../common');

Expand Down Expand Up @@ -34,7 +34,7 @@
await new Promise((resolve, reject) => {
session1.post('Debugger.setBreakpointByUrl', {
'lineNumber': 12,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'url': decodeURIComponent(pathToFileURL(path.resolve(__dirname, __filename)).toString()),
'columnNumber': 0,
'condition': ''
}, (error, result) => {
Expand Down
67 changes: 67 additions & 0 deletions test/parallel/test-inspector-uriencode~d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const assert = require('assert');
const { Session } = require('inspector');
const path = require('path');
const { pathToFileURL } = require('url');

function debugged() {
return 42;
}

async function test() {
// Check without properly decoding
const session1 = new Session();
session1.connect();
let session1Paused = false;
session1.on('Debugger.paused', () => session1Paused = true);
session1.post('Debugger.enable');

await new Promise((resolve, reject) => {
session1.post('Debugger.setBreakpointByUrl', {
'lineNumber': 12,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'columnNumber': 0,
'condition': ''
}, (error, result) => {
return error ? reject(error) : resolve(result);
});
});

debugged();

assert(!session1Paused);
session1.disconnect();

// Check correctly with another session
let session2Paused = false;
const session2 = new Session();
session2.connect();
session2.on('Debugger.paused', () => session2Paused = true);
session2.post('Debugger.enable');

await new Promise((resolve, reject) => {
session2.post('Debugger.setBreakpointByUrl', {
'lineNumber': 12,
'url': decodeURIComponent(pathToFileURL(path.resolve(__dirname, __filename)).toString()),
'columnNumber': 0,
'condition': ''
}, (error, result) => {
return error ? reject(error) : resolve(result);
});
});

debugged();

assert(session2Paused);
session2.disconnect();
}

const interval = setInterval(() => {}, 1000);
test().then(common.mustCall(() => {
clearInterval(interval);
console.log('Done!');
}));
Loading