[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:
Scotty Bollinger 2021-03-08 17:27:17 -06:00 committed by GitHub
parent 4c58e70a7e
commit a0e88ece91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -63,6 +63,15 @@ describe('RoleMappingsTable', () => {
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', () => {
const wrapper = shallow(
<RoleMappingsTable {...props} roleMappings={[asRoleMapping as any]} accessItemKey="engines" />

View file

@ -83,8 +83,10 @@ export const RoleMappingsTable: React.FC<Props> = ({
});
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 regexp = new RegExp(filterValue, 'i');
const regexp = new RegExp(sanitizedValue, 'i');
return values.filter((x) => regexp.test(x)).length > 0;
};