feat(loki-monaco-editor): escape autocompleted label values (#56890)

This commit is contained in:
Matias Chomicki
2022-10-14 10:29:03 +02:00
committed by GitHub
parent e5d644d991
commit 08ffcfdf16
2 changed files with 13 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ const history = [
];
const labelNames = ['place', 'source'];
const labelValues = ['moon', 'luna'];
const labelValues = ['moon', 'luna', 'server\\1'];
const extractedLabelKeys = ['extracted', 'label'];
const otherLabels: Label[] = [
{
@@ -244,6 +244,11 @@ describe('getCompletions', () => {
label: 'luna',
type: 'LABEL_VALUE',
},
{
insertText: '"server\\\\1"',
label: 'server\\1',
type: 'LABEL_VALUE',
},
]);
completions = await getCompletions({ ...situation, betweenQuotes: true }, completionProvider);
@@ -259,6 +264,11 @@ describe('getCompletions', () => {
label: 'luna',
type: 'LABEL_VALUE',
},
{
insertText: 'server\\\\1',
label: 'server\\1',
type: 'LABEL_VALUE',
},
]);
});

View File

@@ -1,3 +1,4 @@
import { escapeLabelValueInExactSelector } from '../../../languageUtils';
import { AGGREGATION_OPERATORS, RANGE_VEC_FUNCTIONS } from '../../../syntax';
import { CompletionDataProvider } from './CompletionDataProvider';
@@ -197,7 +198,7 @@ async function getLabelValuesForMetricCompletions(
return values.map((text) => ({
type: 'LABEL_VALUE',
label: text,
insertText: betweenQuotes ? text : `"${text}"`,
insertText: betweenQuotes ? escapeLabelValueInExactSelector(text) : `"${escapeLabelValueInExactSelector(text)}"`,
}));
}