Transformations: Add string type check to field value in substring value matcher (#87782)

This commit is contained in:
Nathan Marrs 2024-05-14 17:56:46 -06:00 committed by GitHub
parent 012ee1d557
commit d92ec98ecc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -9,7 +9,7 @@ describe('value substring to matcher', () => {
fields: [
{
name: 'temp',
values: ['24', null, '10', 'asd', '42', 'ASD'],
values: ['24', null, '10', 'asd', '42', 'ASD', [1, 2, 3]],
},
],
}),
@ -53,6 +53,14 @@ describe('value substring to matcher', () => {
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
});
it('should be a mismatch if the option is an array / non-string and should not cause errors', () => {
const frame = data[0];
const field = frame.fields[0];
const valueIndex = 6;
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
});
it('should not match when option value is different', () => {
const frame = data[0];
const field = frame.fields[0];

View File

@ -12,7 +12,11 @@ const isSubstringMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
return (valueIndex: number, field: Field) => {
const value = field.values[valueIndex];
return (
(value && options.value && value.toLowerCase().includes(options.value.toLowerCase())) || options.value === ''
(value &&
options.value &&
typeof value === 'string' &&
value.toLowerCase().includes(options.value.toLowerCase())) ||
options.value === ''
);
};
},