From b01194f81ecec134aff488fbc0609921a2b2c3d5 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Wed, 29 Mar 2023 15:00:42 +0200 Subject: [PATCH] Loki: Fix autocomplete situations with multiple escaped quotes (#65520) fix situations with multiple quotes --- .../monaco-completion-provider/situation.test.ts | 6 ++++++ .../monaco-completion-provider/situation.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.test.ts b/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.test.ts index 7541f563fb4..84ae6d606e6 100644 --- a/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.test.ts +++ b/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.test.ts @@ -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', () => { diff --git a/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts b/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts index fbee96313ba..891dc320966 100644 --- a/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts +++ b/public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts @@ -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