[ES|QL] Fixes warnings with escaped quotes (#213685)

## Summary

Fixes a big where the warning appear wrong when the warning message has
escaped quotes.

**Before**
![image
(84)](https://github.com/user-attachments/assets/db7eaca1-bb04-4785-ae3e-2ecb3da694ee)


**Now**

![image](https://github.com/user-attachments/assets/afc107e1-b83d-4d3b-862c-6c2bffc27656)



### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios


Brought at my attention from @nik9000 ❤️

---------

Co-authored-by: Dima Arnautov <arnautov.dima@gmail.com>
This commit is contained in:
Stratoula Kalafateli 2025-03-11 13:48:45 +01:00 committed by GitHub
parent ba13e86a70
commit 0addb3fd6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 2 deletions

View file

@ -202,6 +202,36 @@ describe('helpers', function () {
},
]);
});
it('should return the correct array of warningsif the quotes are escaped (at that case we dont have a new warning)', function () {
const warning = `299 Elasticsearch-9.1.0 "No limit defined, adding default limit of [1000]", "Line 1:9: evaluation of [TO_LOWER([\\"FOO\\", \\"BAR\\"])] failed", "Line 1:9: java.lang.IllegalArgumentException: single-value function encountered multi-value"`;
expect(parseWarning(warning)).toEqual([
{
endColumn: 10,
endLineNumber: 1,
message: 'No limit defined, adding default limit of [1000]',
severity: 4,
startColumn: 1,
startLineNumber: 1,
},
{
endColumn: 40,
endLineNumber: 1,
message: 'evaluation of [TO_LOWER(["FOO", "BAR"])] failed',
severity: 4,
startColumn: 9,
startLineNumber: 1,
},
{
endColumn: 18,
endLineNumber: 1,
message: 'single-value function encountered multi-value',
severity: 4,
startColumn: 9,
startLineNumber: 1,
},
]);
});
});
describe('getIndicesList', function () {

View file

@ -63,7 +63,10 @@ export const useDebounceWithOptions = (
);
};
const quotedWarningMessageRegexp = /"(.*?)"/g;
// Quotes can be used as separators for multiple warnings unless
// they are escaped with backslashes. This regexp will match any
// quoted string that is not escaped.
const quotedWarningMessageRegexp = /"(?:[^"\\]*(?:\\.[^"\\]*)*)"/g;
export const parseWarning = (warning: string): MonacoMessage[] => {
if (quotedWarningMessageRegexp.test(warning)) {
@ -71,7 +74,8 @@ export const parseWarning = (warning: string): MonacoMessage[] => {
if (matches) {
return matches.map((message) => {
// start extracting the quoted message and with few default positioning
let warningMessage = message.replace(/"/g, '');
// replaces the quotes only if they are not escaped
let warningMessage = message.replace(/(?<!\\)"|\\/g, '');
let startColumn = 1;
let startLineNumber = 1;
// initialize the length to 10 in case no error word found