[Enterprise Search] Fix bug where special chars breaks UI (#94000)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
4c58e70a7e
commit
a0e88ece91
|
@ -63,6 +63,15 @@ describe('RoleMappingsTable', () => {
|
||||||
expect(wrapper.find(EuiTableRow)).toHaveLength(0);
|
expect(wrapper.find(EuiTableRow)).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles input change with special chars', () => {
|
||||||
|
const wrapper = shallow(<RoleMappingsTable {...props} />);
|
||||||
|
const input = wrapper.find(EuiFieldSearch);
|
||||||
|
const value = '*//username';
|
||||||
|
input.simulate('change', { target: { value } });
|
||||||
|
|
||||||
|
expect(wrapper.find(EuiTableRow)).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('shows default message when "accessAllEngines" is true', () => {
|
it('shows default message when "accessAllEngines" is true', () => {
|
||||||
const wrapper = shallow(
|
const wrapper = shallow(
|
||||||
<RoleMappingsTable {...props} roleMappings={[asRoleMapping as any]} accessItemKey="engines" />
|
<RoleMappingsTable {...props} roleMappings={[asRoleMapping as any]} accessItemKey="engines" />
|
||||||
|
|
|
@ -83,8 +83,10 @@ export const RoleMappingsTable: React.FC<Props> = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const filterResults = (result: SharedRoleMapping) => {
|
const filterResults = (result: SharedRoleMapping) => {
|
||||||
|
// Filter out non-alphanumeric characters, except for underscores, hyphens, and spaces
|
||||||
|
const sanitizedValue = filterValue.replace(/[^\w\s-]/g, '');
|
||||||
const values = Object.values(result);
|
const values = Object.values(result);
|
||||||
const regexp = new RegExp(filterValue, 'i');
|
const regexp = new RegExp(sanitizedValue, 'i');
|
||||||
return values.filter((x) => regexp.test(x)).length > 0;
|
return values.filter((x) => regexp.test(x)).length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue