Skip to content

Commit

Permalink
[ES|QL] Harden regular expressions (elastic#193247)
Browse files Browse the repository at this point in the history
## Summary

Partially addresses elastic/kibana-team#1087

- Changes a regex from "polynomial" complexity to "safe".
- Removes a regex in favor or plain JS string manipulation.
  • Loading branch information
vadimkibana authored Sep 18, 2024
1 parent 59a0ca2 commit 6a3adf7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/antlr_error_listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ErrorListener } from 'antlr4';
import type { EditorError } from './types';
import { getPosition } from './ast_position_utils';

const REPLACE_DEV = /,*\s*DEV_\w+\s*/g;
const REPLACE_DEV = /,{0,1}(?<!\s)\s*DEV_\w+\s*/g;
export class ESQLErrorListener extends ErrorListener<any> {
protected errors: EditorError[] = [];

Expand Down
14 changes: 8 additions & 6 deletions packages/kbn-text-based-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ export const parseWarning = (warning: string): MonacoMessage[] => {
startColumn = Number(encodedColumn);
startLineNumber = Number(encodedLine.replace('Line ', ''));
}
// extract the length of the "expression" within the message
// and try to guess the correct size for the editor marker to highlight
if (/\[.*\]/.test(warningMessage)) {
const [_, wordWithError] = warningMessage.split('[');
if (wordWithError) {
errorLength = wordWithError.length;
const openingSquareBracketIndex = warningMessage.indexOf('[');
if (openingSquareBracketIndex !== -1) {
const closingSquareBracketIndex = warningMessage.indexOf(
']',
openingSquareBracketIndex
);
if (closingSquareBracketIndex !== -1) {
errorLength = warningMessage.length - openingSquareBracketIndex - 1;
}
}
}
Expand Down

0 comments on commit 6a3adf7

Please sign in to comment.