diff --git a/error-stack-parser.js b/error-stack-parser.js index 5231091..f8e16da 100644 --- a/error-stack-parser.js +++ b/error-stack-parser.js @@ -42,9 +42,10 @@ if (urlLike.indexOf(':') === -1) { return [urlLike]; } - + // strip any parentheses from start and end of string (but not from inside) + var withoutParens = urlLike.replace(/^\(+/, '').replace(/\)+$/, ''); var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/; - var parts = regExp.exec(urlLike.replace(/[()]/g, '')); + var parts = regExp.exec(withoutParens); return [parts[1], parts[2] || undefined, parts[3] || undefined]; }, diff --git a/spec/error-stack-parser-spec.js b/spec/error-stack-parser-spec.js index 8177b16..701db17 100644 --- a/spec/error-stack-parser-spec.js +++ b/spec/error-stack-parser-spec.js @@ -233,5 +233,13 @@ describe('ErrorStackParser', function() { expect(stackframes[1].lineNumber).toBe(2); expect(stackframes[1].columnNumber).toBe(9); }); + + it('should handle parentheses in filenames', function() { + var stackframes = unit.parse(CapturedExceptions.NODE_WITH_PARENTHESES); + expect(stackframes.length).toBe(7); + expect(stackframes[0].fileName).toEqual('/var/app/scratch/my project (top secret)/index.js'); + expect(stackframes[0].lineNumber).toBe(2); + expect(stackframes[0].columnNumber).toBe(9); + }); }); }); diff --git a/spec/fixtures/captured-errors.js b/spec/fixtures/captured-errors.js index f7ff703..bffd6ab 100644 --- a/spec/fixtures/captured-errors.js +++ b/spec/fixtures/captured-errors.js @@ -398,3 +398,17 @@ CapturedExceptions.NODE_WITH_SPACES = { 'Function.Module.runMain (internal/modules/cjs/loader.js:837:10)\n at ' + 'internal/main/run_main_module.js:17:11' }; + +CapturedExceptions.NODE_WITH_PARENTHESES = { + name: 'Error', + message: '', + stack: 'Error\n at Object. ' + + '(/var/app/scratch/my ' + + 'project (top secret)/index.js:2:9)\n at Module._compile ' + + '(internal/modules/cjs/loader.js:774:30)\n at ' + + 'Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)\n ' + + ' at Module.load (internal/modules/cjs/loader.js:641:32)\n at ' + + 'Function.Module._load (internal/modules/cjs/loader.js:556:12)\n at ' + + 'Function.Module.runMain (internal/modules/cjs/loader.js:837:10)\n at ' + + 'internal/main/run_main_module.js:17:11' +};