diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/__snapshots__/index.test.tsx.snap
index 5f529ba827c45..26b9eb4729999 100644
--- a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/__snapshots__/index.test.tsx.snap
+++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/__snapshots__/index.test.tsx.snap
@@ -274,7 +274,7 @@ In other use cases the message field can be used to concatenate different values
]
}
kqlMode="search"
- kqlQueryExpression=""
+ kqlQueryExpression=" "
onEventClosed={[MockFunction]}
renderCellValue={[Function]}
rowRenderers={
diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.test.tsx
index cd9693313b4f9..2fc8c2149c35b 100644
--- a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.test.tsx
+++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.test.tsx
@@ -25,6 +25,7 @@ import { useTimelineEventsDetails } from '../../../containers/details/index';
import { useSourcererScope } from '../../../../common/containers/sourcerer';
import { mockSourcererScope } from '../../../../common/containers/sourcerer/mocks';
import { Direction } from '../../../../../common/search_strategy';
+import * as helpers from '../helpers';
jest.mock('../../../containers/index', () => ({
useTimelineEvents: jest.fn(),
@@ -116,7 +117,7 @@ describe('Timeline', () => {
itemsPerPage: 5,
itemsPerPageOptions: [5, 10, 20],
kqlMode: 'search' as QueryTabContentComponentProps['kqlMode'],
- kqlQueryExpression: '',
+ kqlQueryExpression: ' ',
onEventClosed: jest.fn(),
renderCellValue: DefaultCellRenderer,
rowRenderers: defaultRowRenderers,
@@ -133,6 +134,27 @@ describe('Timeline', () => {
});
describe('rendering', () => {
+ let spyCombineQueries: jest.SpyInstance;
+
+ beforeEach(() => {
+ spyCombineQueries = jest.spyOn(helpers, 'combineQueries');
+ });
+ afterEach(() => {
+ spyCombineQueries.mockClear();
+ });
+
+ test('should trim kqlQueryExpression', () => {
+ mount(
+
+
+
+ );
+
+ expect(spyCombineQueries.mock.calls[0][0].kqlQuery.query).toEqual(
+ props.kqlQueryExpression.trim()
+ );
+ });
+
test('renders correctly against snapshot', () => {
const wrapper = shallow(
diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx
index 3dc2d98f16462..c150f1a44f196 100644
--- a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx
+++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx
@@ -209,7 +209,9 @@ export const QueryTabContentComponent: React.FC = ({
const kqlQuery: {
query: string;
language: KueryFilterQueryKind;
- } = useMemo(() => ({ query: kqlQueryExpression, language: 'kuery' }), [kqlQueryExpression]);
+ } = useMemo(() => ({ query: kqlQueryExpression.trim(), language: 'kuery' }), [
+ kqlQueryExpression,
+ ]);
const combinedQueries = combineQueries({
config: esQueryConfig,