Skip to content

Commit 5ddf7f4

Browse files
bajtosbnoordhuis
authored andcommitted
debugger: fix bug in breakpoint regex escaping
Fix a bug in setBreakpoint() where not all regex characters are escaped when constructing scriptRegEx for V8.
1 parent 179784e commit 5ddf7f4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/_debugger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ Interface.prototype.setBreakpoint = function(script, line,
13981398
};
13991399
} else {
14001400
this.print('Warning: script \'' + script + '\' was not loaded yet.');
1401-
var normalizedPath = script.replace('([/.?*])', '\\$1');
1402-
var scriptPathRegex = '^(.*[\\/\\\\])?' + normalizedPath + '$';
1401+
var escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
1402+
var scriptPathRegex = '^(.*[\\/\\\\])?' + escapedPath + '$';
14031403
req = {
14041404
type: 'scriptRegExp',
14051405
target: scriptPathRegex,

test/simple/test-debugger-repl-break-in-module.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ repl.addTest('sb("mod.js", 23)', [
3131
/1/, /2/, /3/, /4/, /5/, /6/
3232
]);
3333

34+
// Check escaping of regex characters
35+
repl.addTest('sb(")^$*+?}{|][(.js\\\\", 1)', [
36+
/Warning: script '[^']+' was not loaded yet\./,
37+
/1/, /2/, /3/, /4/, /5/, /6/
38+
]);
39+
3440
// continue - the breakpoint should be triggered
3541
repl.addTest('c', [
3642
/break in .*[\\\/]mod\.js:23/,
@@ -47,7 +53,9 @@ repl.addTest('restart', [].concat(
4753
repl.handshakeLines,
4854
[
4955
/Restoring breakpoint mod.js:23/,
50-
/Warning: script 'mod\.js' was not loaded yet\./
56+
/Warning: script 'mod\.js' was not loaded yet\./,
57+
/Restoring breakpoint \).*:\d+/,
58+
/Warning: script '\)[^']*' was not loaded yet\./
5159
],
5260
repl.initialBreakLines));
5361

0 commit comments

Comments
 (0)