[8.6] Fix overly permissive regular expression range (#150058) (#150324)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Fix overly permissive regular expression range
(#150058)](https://github.com/elastic/kibana/pull/150058)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Thomas
Watson","email":"watson@elastic.co"},"sourceCommit":{"committedDate":"2023-02-06T13:05:08Z","message":"Fix
overly permissive regular expression range (#150058)\n\nWithout escaping
`-`, it's treated as a range instead of the literal\r\ncharacter - i.e.
it matches everything between `+` and `=` in the ASCII\r\ntable which
for instance include all
numbers.","sha":"af3ae7b5559580b5b7c720afec7d48bf42e24f0c","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v8.7.0"],"number":150058,"url":"https://github.com/elastic/kibana/pull/150058","mergeCommit":{"message":"Fix
overly permissive regular expression range (#150058)\n\nWithout escaping
`-`, it's treated as a range instead of the literal\r\ncharacter - i.e.
it matches everything between `+` and `=` in the ASCII\r\ntable which
for instance include all
numbers.","sha":"af3ae7b5559580b5b7c720afec7d48bf42e24f0c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/150058","number":150058,"mergeCommit":{"message":"Fix
overly permissive regular expression range (#150058)\n\nWithout escaping
`-`, it's treated as a range instead of the literal\r\ncharacter - i.e.
it matches everything between `+` and `=` in the ASCII\r\ntable which
for instance include all
numbers.","sha":"af3ae7b5559580b5b7c720afec7d48bf42e24f0c"}}]}]
BACKPORT-->

Co-authored-by: Thomas Watson <watson@elastic.co>
This commit is contained in:
Kibana Machine 2023-02-06 09:11:31 -05:00 committed by GitHub
parent cb7d76d976
commit a751fd5f47
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');