[8.6] Fix escaping of double quote (#150039) (#150055)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Fix escaping of double quote
(#150039)](https://github.com/elastic/kibana/pull/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":"watson@elastic.co"},"sourceCommit":{"committedDate":"2023-02-01T14:00:22Z","message":"Fix
escaping of double quote (#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 (#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 (#150039)\n\nThe previous version of
`escapeSearchQueryPhrase` didn't
escape\r\nanything.","sha":"13853a4a5bc70726ddf9168b13eea0e8013bf360"}}]}]
BACKPORT-->

Co-authored-by: Thomas Watson <watson@elastic.co>
This commit is contained in:
Kibana Machine 2023-02-01 10:05:29 -05:00 committed by GitHub
parent 1c89d27ff7
commit 9a1a960b46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -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"`);
});
});
});

View file

@ -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