mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
ui: escape label values in PromQL autocomplete
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This commit is contained in:
parent
cf4505c6cd
commit
7c6bab8c58
3 changed files with 16 additions and 2 deletions
|
|
@ -1568,6 +1568,14 @@ describe('autocomplete promQL test', () => {
|
|||
label: 'demo',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
label: '\\\\x2d',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
label: 'quoted\\"value',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
from: 25,
|
||||
to: 25,
|
||||
|
|
|
|||
|
|
@ -168,6 +168,10 @@ function arrayToCompletionResult(data: Completion[], from: number, to: number, i
|
|||
} as CompletionResult;
|
||||
}
|
||||
|
||||
function escapePromQLString(str: string): string {
|
||||
return str.replace(/([\\"])/g, '\\$1');
|
||||
}
|
||||
|
||||
// computeEndCompletePosition calculates the end position for autocompletion replacement.
|
||||
// When the cursor is in the middle of a token, this ensures the entire token is replaced,
|
||||
// not just the portion before the cursor. This fixes issue #15839.
|
||||
|
|
@ -794,7 +798,7 @@ export class HybridComplete implements CompleteStrategy {
|
|||
return result;
|
||||
}
|
||||
return this.prometheusClient.labelValues(context.labelName, context.metricName, context.matchers).then((labelValues: string[]) => {
|
||||
return result.concat(labelValues.map((value) => ({ label: value, type: 'text' })));
|
||||
return result.concat(labelValues.map((value) => ({ label: escapePromQLString(value), type: 'text' })));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"status": "success",
|
||||
"data": [
|
||||
"demo"
|
||||
"demo",
|
||||
"\\x2d",
|
||||
"quoted\"value"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue