Skip to content
Merged
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
19 changes: 10 additions & 9 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,17 @@ function isSetup() {
function joinRegExp(patterns) {
// Combine an array of regular expressions and strings into one large regexp
// Be mad.
var sources = [], i = patterns.length;
while (i--) {
if (!isUndefined(patterns[i]) && patterns[i]) {
sources[i] = isString(patterns[i]) ?
// If it's a string, we need to escape it
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") :
// If it's a regexp already, we want to extract the source
patterns[i].source;
var sources = [], len = patterns.length;
for (var i = 0; i < len; i++) {
if (isString(patterns[i])) {
// If it's a string, we need to escape it
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
sources.push(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
} else if (patterns[i] && patterns[i].source) {
// If it's a regexp already, we want to extract the source
sources.push(patterns[i].source);
}
// Intentionally skip other cases
}
return new RegExp(sources.join('|'), 'i');
}
Expand Down
6 changes: 6 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ describe('globals', function() {
'a', 'b', null, undefined
]).source, 'a|b');
});

it('should skip entries that are not strings or regular expressions in the passed array of patterns', function() {
assert.equal(joinRegExp([
'a', 'b', null, 'a.b', undefined, true, /d/, 123, {}, /[0-9]/, []
]).source, 'a|b|a\\.b|d|[0-9]');
});
});
});

Expand Down