Loki: Fix autocomplete situations with multiple escaped quotes (#65520)

fix situations with multiple quotes
This commit is contained in:
Sven Grossmann 2023-03-29 15:00:42 +02:00 committed by GitHub
parent 5c138e16d7
commit b01194f81e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -154,6 +154,12 @@ describe('situation', () => {
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
otherLabels: [{ name: 'one', value: 'val\\"1', op: '=' }],
});
// double-quoted label-values with escape and multiple quotes
assertSituation('{one="val\\"1\\"",^}', {
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
otherLabels: [{ name: 'one', value: 'val"1"', op: '=' }],
});
});
it('identifies AFTER_UNWRAP autocomplete situations', () => {

View File

@ -63,14 +63,14 @@ function parseStringLiteral(text: string): string {
if (text.startsWith('"') && text.endsWith('"')) {
// NOTE: this is not 100% perfect, we only unescape the double-quote,
// there might be other characters too
return inside.replace(/\\"/, '"');
return inside.replace(/\\"/gm, '"');
}
// Single quotes
if (text.startsWith("'") && text.endsWith("'")) {
// NOTE: this is not 100% perfect, we only unescape the single-quote,
// there might be other characters too
return inside.replace(/\\'/, "'");
return inside.replace(/\\'/gm, "'");
}
// Backticks