mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-04 20:06:12 +02:00
Refactor duration regex and remove RegExp.escape polyfill
Removed polyfill for RegExp.escape and updated duration regex. Signed-off-by: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com>
This commit is contained in:
parent
42418660d3
commit
49427cfcd2
@ -166,22 +166,9 @@ function arrayToCompletionResult(data: Completion[], from: number, to: number, i
|
||||
} as CompletionResult;
|
||||
}
|
||||
|
||||
// Polyfill RegExp.escape for compatibility with ES2024 and TypeScript.
|
||||
// Ensures safe, standards-based regex escaping in all environments.
|
||||
declare global {
|
||||
interface RegExpConstructor {
|
||||
escape?: (s: string) => string;
|
||||
}
|
||||
}
|
||||
|
||||
if (!RegExp.escape) {
|
||||
RegExp.escape = function (s: string): string {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
};
|
||||
}
|
||||
|
||||
// Matches complete PromQL durations, including compound units (e.g., 5m, 1d2h, 1h30m, etc.)
|
||||
export const durationWithUnitRegexp = new RegExp(`^(\\d+(${durationTerms.map((term) => RegExp.escape!(term.label)).join('|')}))+$`);
|
||||
// Matches complete PromQL durations, including compound units (e.g., 5m, 1d2h, 1h30m, etc.).
|
||||
// Duration units are a fixed, safe set (no regex metacharacters), so no escaping is needed.
|
||||
export const durationWithUnitRegexp = new RegExp(`^(\\d+(${durationTerms.map((term) => term.label).join('|')}))+$`);
|
||||
|
||||
// Determines if a duration already has a complete time unit to prevent autocomplete insertion (issue #15452)
|
||||
function hasCompleteDurationUnit(state: EditorState, node: SyntaxNode): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user