From 5ddf7f4200894a7304d7c07bbbd8773fac3509d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 29 Apr 2013 14:09:26 +0200 Subject: [PATCH] debugger: fix bug in breakpoint regex escaping Fix a bug in setBreakpoint() where not all regex characters are escaped when constructing scriptRegEx for V8. --- lib/_debugger.js | 4 ++-- test/simple/test-debugger-repl-break-in-module.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index 170f5e7e6e..10096b5eaa 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -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, diff --git a/test/simple/test-debugger-repl-break-in-module.js b/test/simple/test-debugger-repl-break-in-module.js index ddf17f8ee1..1fe0aba841 100644 --- a/test/simple/test-debugger-repl-break-in-module.js +++ b/test/simple/test-debugger-repl-break-in-module.js @@ -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/, @@ -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));