Elasticsearch: Fix modify query with backslashes (#79430)

* Elasticsearch: Fix modify query with backslashes

* add test devenv
This commit is contained in:
Sven Grossmann
2023-12-13 14:07:46 +01:00
committed by GitHub
parent 91836e7832
commit db7fa30384
3 changed files with 14 additions and 3 deletions
+2 -1
View File
@@ -149,7 +149,8 @@ function getRandomLogItem(counter, timestamp) {
hostname: chooseRandomElement(['hostname1', 'hostname2', 'hostname3', 'hostname4', 'hostname5', 'hostname6']),
value: counter,
metric: chooseRandomElement(['cpu', 'memory', 'latency']),
description: "this is description"
description: "this is description",
slash: "Access to the path '\\\\tkasnpo\\KASNPO\\Files\\contacts.xml' is denied."
};
}
@@ -126,4 +126,13 @@ describe('addStringFilterToQuery', () => {
expect(addStringFilterToQuery('label:"value"', '"filter"')).toBe('label:"value" AND "\\"filter\\""');
expect(addStringFilterToQuery('label:"value"', '"filter"', false)).toBe('label:"value" NOT "\\"filter\\""');
});
it('should escape filter values with backslashes', () => {
expect(addStringFilterToQuery('label:"value"', '"filter with \\"')).toBe(
'label:"value" AND "\\"filter with \\\\\\""'
);
expect(addStringFilterToQuery('label:"value"', '"filter with \\"', false)).toBe(
'label:"value" NOT "\\"filter with \\\\\\""'
);
});
});
@@ -63,8 +63,8 @@ export function addFilterToQuery(query: string, key: string, value: string, modi
return query;
}
key = lucene.term.escape(key);
value = lucene.phrase.escape(value);
key = escapeFilter(key);
value = escapeFilterValue(value);
const filter = `${modifier}${key}:"${value}"`;
return concatenate(query, filter);
@@ -187,6 +187,7 @@ export function escapeFilter(value: string) {
* Use this function to escape filter values.
*/
export function escapeFilterValue(value: string) {
value = value.replace(/\\/g, '\\\\');
return lucene.phrase.escape(value);
}