mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[KQL] Fix handling of backslashes when autocompleting values (#85457)
* [KQL] Fix handling of backslashes when autocompleting values * Revert change to test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
4b2c9de638
commit
272b2d0628
2 changed files with 12 additions and 1 deletions
|
@ -14,6 +14,13 @@ describe('Kuery escape', () => {
|
|||
expect(escapeQuotes(value)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should escape backslashes and quotes', () => {
|
||||
const value = 'Backslashes \\" in the middle and ends with quotes \\"';
|
||||
const expected = 'Backslashes \\\\\\" in the middle and ends with quotes \\\\\\"';
|
||||
|
||||
expect(escapeQuotes(value)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should escape special characters', () => {
|
||||
const value = `This \\ has (a lot of) <special> characters, don't you *think*? "Yes."`;
|
||||
const expected = `This \\\\ has \\(a lot of\\) \\<special\\> characters, don't you \\*think\\*? \\"Yes.\\"`;
|
||||
|
|
|
@ -6,8 +6,12 @@
|
|||
|
||||
import { flow } from 'lodash';
|
||||
|
||||
/**
|
||||
* Escapes backslashes and double-quotes. (Useful when putting a string in quotes to use as a value
|
||||
* in a KQL expression. See the QuotedCharacter rule in kuery.peg.)
|
||||
*/
|
||||
export function escapeQuotes(str: string) {
|
||||
return str.replace(/"/g, '\\"');
|
||||
return str.replace(/[\\"]/g, '\\$&');
|
||||
}
|
||||
|
||||
export const escapeKuery = flow(escapeSpecialCharacters, escapeAndOr, escapeNot, escapeWhitespace);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue