Skip to content

prevent parentheses in filenames being stripped out #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 3 additions & 2 deletions error-stack-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
},

Expand Down
8 changes: 8 additions & 0 deletions spec/error-stack-parser-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
14 changes: 14 additions & 0 deletions spec/fixtures/captured-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> ' +
'(/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'
};