Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiInMemoryTable] Syntax error when searching with special characters #7160

Closed
cee-chen opened this issue Sep 6, 2023 · 5 comments · Fixed by #7175
Closed

[EuiInMemoryTable] Syntax error when searching with special characters #7160

cee-chen opened this issue Sep 6, 2023 · 5 comments · Fixed by #7175
Assignees

Comments

@cee-chen
Copy link
Contributor

cee-chen commented Sep 6, 2023

Problem

See elastic/kibana#138499

The security team is using our in memory table's built-in search API for what's essentially plain text search. Unfortunately, some of the strings they're searching for have special characters in them, and the underlying EuiSearchBar component that the table uses throws a syntax error when the search string contains a special character.

Possible solutions

  1. Addressing within EuiSearchBar: one approach could be something similar to what was done in [EuiSearchBar] Automatically wrap special characters (that aren't used in EQL syntax) in quotes #6356 (NOTE: this auto-escaping was only performed for terms/types and not for top-level searches).

  2. Addressing within EuiInMemoryTable: essentially the use-case for the above Kibana issue doesn't need the EQL behavior of EuiSearchBar whatsoever. We could consider adding a prop to the search obj that allows consumers to specify they simply want to use a plaintext EuiFieldSearch component instead of the full-blown EQL syntax, and search based on that.

Timeline

Hoping to pick this up during my support week this week, but if not, we should triage priority at our next grooming meeting

@cee-chen cee-chen changed the title [EuiInMemoryTable] Syntax error when searching for fields with special characters in them [EuiInMemoryTable] Syntax error when searching with special characters Sep 6, 2023
@cee-chen
Copy link
Contributor Author

cee-chen commented Sep 7, 2023

@janmonschke I'm experimenting with auto-escaping more special characters in EuiSearchBar under the hood. Unfortunately, the following characters will never be correctly escaped/handled by the search bar, because they're special characters used to interpret EQL: ", (), : and \.

Just curious, what do you think is the likelihood of your team's products having items with the above characters? If the answer is likely, we'll probably need to look into avoiding EuiSearchBar/EQL completely and figuring out some other way of iterating/searching over all provided items.

@janmonschke
Copy link
Contributor

(),

Those might be the only ones that I can think of. But at that point it's become such an edge case, that I think we'll see the 'false positive' error very rarely :)

@cee-chen
Copy link
Contributor Author

cee-chen commented Sep 9, 2023

Good news - I'm down to just \ throwing errors/breaking EQL (EDIT: Thanks to Tomasz, every special character now works! 🎉 ) :) #7175 if you're curious to check it out ahead of time!

Note: It's still using EQL under the hood to execute over every item, which perhaps isn't as performant as it could be, but it's at least not less performant than current behavior.

@cee-chen cee-chen self-assigned this Sep 9, 2023
@cee-chen
Copy link
Contributor Author

Just as a quick update - the upcoming API to enable searching for special characters is:

<EuiInMemoryTable
  search={true}
  searchFormat="text"
  // ... other props
/>

Please note that filters will not work at all when using this search format, so this truly should only be used for plain text search.

@cee-chen
Copy link
Contributor Author

cee-chen commented Sep 18, 2023

🤦 Ahhh, shoot. I just noticed the screenshots in the linked Kibana issue have an "only favorites" filter, which will stop working if used in conjunction with searchFormat="text". So, @janmonschke I don't think your team can use this new feature after all...

I'm experimenting with auto-escaping more special characters in EuiSearchBar under the hood. Unfortunately, the following characters will never be correctly escaped/handled by the search bar, because they're special characters used to interpret EQL: ", (), : and \.

If your team wants to preserve the "Only favorites" filter, this has to be the approach taken. We simply cannot parse the above special characters if EQL for filtering is also being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants