Skip to content

Commit

Permalink
[8.6] Fix escaping of double quote (elastic#150039) (elastic#150055)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.6`:
- [Fix escaping of double quote
(elastic#150039)](elastic#150039)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Thomas
Watson","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-02-01T14:00:22Z","message":"Fix
escaping of double quote (elastic#150039)\n\nThe previous version of
`escapeSearchQueryPhrase` didn't
escape\r\nanything.","sha":"13853a4a5bc70726ddf9168b13eea0e8013bf360","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","backport:all-open","v8.7.0"],"number":150039,"url":"https://github.com/elastic/kibana/pull/150039","mergeCommit":{"message":"Fix
escaping of double quote (elastic#150039)\n\nThe previous version of
`escapeSearchQueryPhrase` didn't
escape\r\nanything.","sha":"13853a4a5bc70726ddf9168b13eea0e8013bf360"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/150039","number":150039,"mergeCommit":{"message":"Fix
escaping of double quote (elastic#150039)\n\nThe previous version of
`escapeSearchQueryPhrase` didn't
escape\r\nanything.","sha":"13853a4a5bc70726ddf9168b13eea0e8013bf360"}}]}]
BACKPORT-->

Co-authored-by: Thomas Watson <[email protected]>
  • Loading branch information
kibanamachine and Thomas Watson authored Feb 1, 2023
1 parent 1c89d27 commit 9a1a960
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/services/saved_object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`);
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/services/saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a1a960

Please sign in to comment.