Skip to content

Improved solution to issue #179 (invalid options throwing errors in joinRegExp) #180

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

Merged
merged 3 commits into from
Jan 12, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,15 @@ function joinRegExp(patterns) {
// 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;
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.unshift(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
} else if (!isUndefined(patterns[i]) && patterns[i] && patterns[i].source) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to check again for isUndefined? Wouldn't just patterns[i] && patterns[i].source be enough?

// If it's a regexp already, we want to extract the source
sources.unshift(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