Fix overly permissive regular expression range (#150058)

Without escaping `-`, it's treated as a range instead of the literal
character - i.e. it matches everything between `+` and `=` in the ASCII
table which for instance include all numbers.
This commit is contained in:
Thomas Watson 2023-02-06 14:05:08 +01:00 committed by GitHub
parent 1ba94ec11c
commit af3ae7b555
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -23,7 +23,7 @@ function escapeRegExp(str: string) {
// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
function escapeQueryString(str: string) {
return str.replace(/[+-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
return str.replace(/[+\-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
}
export function isNode(node: KueryNode): node is KqlWildcardNode {

View file

@ -36,4 +36,4 @@ export const parseSearchString = (query: string) => {
};
const escapeReservedCharacters = (clause: string) =>
clause.replace(/([+-=!\(\)\{\}\[\]^"~*?:\\/!]|&&|\|\|)/g, '\\$1');
clause.replace(/([+\-=!\(\)\{\}\[\]^"~*?:\\/!]|&&|\|\|)/g, '\\$1');