Skip to content

Commit f3baeee

Browse files
committed
Merge pull request #180 from johnbacon/patch-1
Improved solution to issue #179 (invalid options throwing errors in joinRegExp)
2 parents 61d5b88 + 74b868d commit f3baeee

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/raven.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,17 @@ function isSetup() {
642642
function joinRegExp(patterns) {
643643
// Combine an array of regular expressions and strings into one large regexp
644644
// Be mad.
645-
var sources = [], i = patterns.length;
646-
while (i--) {
647-
if (!isUndefined(patterns[i]) && patterns[i]) {
648-
sources[i] = isString(patterns[i]) ?
649-
// If it's a string, we need to escape it
650-
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
651-
patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") :
652-
// If it's a regexp already, we want to extract the source
653-
patterns[i].source;
645+
var sources = [], len = patterns.length;
646+
for (var i = 0; i < len; i++) {
647+
if (isString(patterns[i])) {
648+
// If it's a string, we need to escape it
649+
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
650+
sources.push(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
651+
} else if (patterns[i] && patterns[i].source) {
652+
// If it's a regexp already, we want to extract the source
653+
sources.push(patterns[i].source);
654654
}
655+
// Intentionally skip other cases
655656
}
656657
return new RegExp(sources.join('|'), 'i');
657658
}

test/raven.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,12 @@ describe('globals', function() {
879879
'a', 'b', null, undefined
880880
]).source, 'a|b');
881881
});
882+
883+
it('should skip entries that are not strings or regular expressions in the passed array of patterns', function() {
884+
assert.equal(joinRegExp([
885+
'a', 'b', null, 'a.b', undefined, true, /d/, 123, {}, /[0-9]/, []
886+
]).source, 'a|b|a\\.b|d|[0-9]');
887+
});
882888
});
883889
});
884890

0 commit comments

Comments
 (0)