Guard against calling fieldWildcardMatcher or fieldWildcardFilter with undefined (#19865)
This commit is contained in:
parent
f5a70272ce
commit
fd22e216fc
|
@ -57,6 +57,18 @@ describe('fieldWildcard', function () {
|
|||
});
|
||||
|
||||
describe('filter', function () {
|
||||
it('filters nothing when given undefined', function () {
|
||||
const filter = fieldWildcardFilter();
|
||||
const original = [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz',
|
||||
1234
|
||||
];
|
||||
|
||||
expect(original.filter(filter)).to.eql(original);
|
||||
});
|
||||
|
||||
it('filters nothing when given an empty array', function () {
|
||||
const filter = fieldWildcardFilter([]);
|
||||
const original = [
|
||||
|
|
|
@ -26,7 +26,8 @@ export function FieldWildcardProvider(config) {
|
|||
return new RegExp('^' + glob.split('*').map(escapeRegExp).join('.*') + '$');
|
||||
});
|
||||
|
||||
function fieldWildcardMatcher(globs) {
|
||||
// Note that this will return an essentially noop function if globs is undefined.
|
||||
function fieldWildcardMatcher(globs = []) {
|
||||
return function matcher(val) {
|
||||
// do not test metaFields or keyword
|
||||
if (metaFields.indexOf(val) !== -1) {
|
||||
|
@ -36,7 +37,8 @@ export function FieldWildcardProvider(config) {
|
|||
};
|
||||
}
|
||||
|
||||
function fieldWildcardFilter(globs) {
|
||||
// Note that this will return an essentially noop function if globs is undefined.
|
||||
function fieldWildcardFilter(globs = []) {
|
||||
const matcher = fieldWildcardMatcher(globs);
|
||||
return function filter(val) {
|
||||
return !matcher(val);
|
||||
|
|
Loading…
Reference in a new issue