eui
eui copied to clipboard
[EuiSearchBar] Allow bad query string
In kibana I am updating the advanced settings page to sync the search text to the query URL search params (https://github.com/elastic/kibana/pull/81829). This allows the URL to possibly be formatted incorrectly. Thus, running Query.parse('category:(accessibility))') will throw an error.
I am testing Query.parse before passing to EuiSearchBar and displaying a warning toast in case of an error. But it would be nice to still update the value of the search bar input element. The only workaround is to set the query to ''.
I would like to propose the query prop as a string allows an incorrectly formatted (aka bad) query string. Currently, passing a bad string will throw an error inside the EuiSearchBar component with no checks on the parsing failure.
https://github.com/elastic/eui/blob/05b3de41656f9e69e0517c56c5344c2b3c035b1d/src/components/search_bar/search_bar.tsx#L101-L103
Looks like the initial state construction for EuiSearchBar needs to get a try/catch that correctly populates the query text & any error.
https://github.com/elastic/eui/blob/bca59468fda3fd29e5176d9ddd375c26b918651f/src/components/search_bar/search_bar.tsx#L122-L127
@chandlerprall, should I just pass an empty string in case if query.text is undefined?
queryText: query.text | ''
Also, I'm not sure if I correctly understand the issue, @nickofthyme, can you please give an example of a bad query string so I can reproduce the error you mentioned?
@Dishebh Yeah, I think '' should be the fallback query when no Query nor string is passed to either defaultQuery or query. I'm not sure if that's already handled.
This issue is focused on the bad query. An example would be 'key:())' note the extra ) at the end.
should I just pass an empty string in case if query.text is undefined?
Should be able to use the provided string in defaultQuery in the error state, something like:
try {
const query = parseQuery(props.defaultQuery || props.query, props);
this.state = {
query,
queryText: query.text,
error: null,
};
} catch(e) {
this.state = {
query: parseQuery(''),
queryText: props.defaultQuery, // I believe this will error in TypeScript, need to very it is a string and still fallback to empty string
error: e.toString(), // maybe e.message? maybe just e?
};
}
👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.