diff --git a/x-pack/plugins/fleet/server/services/saved_object.test.ts b/x-pack/plugins/fleet/server/services/saved_object.test.ts index d2683caf9c725..4dd99a3db2d2b 100644 --- a/x-pack/plugins/fleet/server/services/saved_object.test.ts +++ b/x-pack/plugins/fleet/server/services/saved_object.test.ts @@ -18,7 +18,7 @@ describe('Saved object service', () => { it('should escape quotes', () => { const res = escapeSearchQueryPhrase('test1"test2'); - expect(res).toEqual(`"test1\"test2"`); + expect(res).toEqual(`"test1\\"test2"`); }); }); }); diff --git a/x-pack/plugins/fleet/server/services/saved_object.ts b/x-pack/plugins/fleet/server/services/saved_object.ts index 6a45061d89334..2a1f5e216fb2f 100644 --- a/x-pack/plugins/fleet/server/services/saved_object.ts +++ b/x-pack/plugins/fleet/server/services/saved_object.ts @@ -16,7 +16,7 @@ import type { ListWithKuery } from '../types'; * @param val */ export function escapeSearchQueryPhrase(val: string): string { - return `"${val.replace(/["]/g, '"')}"`; + return `"${val.replace(/["]/g, '\\"')}"`; } // Adds `.attributes` to any kuery strings that are missing it, this comes from