diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.test.tsx
index 22498bbc50c2..9c4737830289 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.test.tsx
@@ -63,6 +63,15 @@ describe('RoleMappingsTable', () => {
expect(wrapper.find(EuiTableRow)).toHaveLength(0);
});
+ it('handles input change with special chars', () => {
+ const wrapper = shallow();
+ 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(
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.tsx
index b6110d692bc9..ae4d65fdf3a4 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/role_mapping/role_mappings_table.tsx
@@ -83,8 +83,10 @@ export const RoleMappingsTable: React.FC = ({
});
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;
};