mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[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**  **Now**  ### 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:
parent
ba13e86a70
commit
0addb3fd6d
2 changed files with 36 additions and 2 deletions
|
@ -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 () {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue