Skip to content

Commit

Permalink
debugger: fix bug in breakpoint regex escaping
Browse files Browse the repository at this point in the history
Fix a bug in setBreakpoint() where not all regex characters are escaped
when constructing scriptRegEx for V8.
  • Loading branch information
bajtos authored and bnoordhuis committed Apr 29, 2013
1 parent 179784e commit 5ddf7f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1398,8 +1398,8 @@ Interface.prototype.setBreakpoint = function(script, line,
};
} else {
this.print('Warning: script \'' + script + '\' was not loaded yet.');
var normalizedPath = script.replace('([/.?*])', '\\$1');
var scriptPathRegex = '^(.*[\\/\\\\])?' + normalizedPath + '$';
var escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
var scriptPathRegex = '^(.*[\\/\\\\])?' + escapedPath + '$';
req = {
type: 'scriptRegExp',
target: scriptPathRegex,
Expand Down
10 changes: 9 additions & 1 deletion test/simple/test-debugger-repl-break-in-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ repl.addTest('sb("mod.js", 23)', [
/1/, /2/, /3/, /4/, /5/, /6/
]);

// Check escaping of regex characters
repl.addTest('sb(")^$*+?}{|][(.js\\\\", 1)', [
/Warning: script '[^']+' was not loaded yet\./,
/1/, /2/, /3/, /4/, /5/, /6/
]);

// continue - the breakpoint should be triggered
repl.addTest('c', [
/break in .*[\\\/]mod\.js:23/,
Expand All @@ -47,7 +53,9 @@ repl.addTest('restart', [].concat(
repl.handshakeLines,
[
/Restoring breakpoint mod.js:23/,
/Warning: script 'mod\.js' was not loaded yet\./
/Warning: script 'mod\.js' was not loaded yet\./,
/Restoring breakpoint \).*:\d+/,
/Warning: script '\)[^']*' was not loaded yet\./
],
repl.initialBreakLines));

Expand Down

0 comments on commit 5ddf7f4

Please sign in to comment.