mirror of https://github.com/grafana/grafana.git
Chore: Fixes cleanNeedle regex to be more specific (#61967)
* Chore: Fixes code sec warning for frontend regex * Update text.ts * Update text.ts
This commit is contained in:
parent
6a93c77082
commit
8e3d22ca7a
|
|
@ -24,7 +24,7 @@ export function findHighlightChunksInText({
|
|||
}
|
||||
|
||||
const cleanNeedle = (needle: string): string => {
|
||||
return needle.replace(/[[{(][\w,.-?:*+]+$/, '');
|
||||
return needle.replace(/[[{(][\w,.\/:;<=>?:*+]+$/, '');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -35,14 +35,17 @@ export function findMatchesInText(haystack: string, needle: string): TextMatch[]
|
|||
if (!haystack || !needle) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const matches: TextMatch[] = [];
|
||||
const { cleaned, flags } = parseFlags(cleanNeedle(needle));
|
||||
let regexp: RegExp;
|
||||
|
||||
try {
|
||||
regexp = new RegExp(`(?:${cleaned})`, flags);
|
||||
} catch (error) {
|
||||
return matches;
|
||||
}
|
||||
|
||||
haystack.replace(regexp, (substring, ...rest) => {
|
||||
if (substring) {
|
||||
const offset = rest[rest.length - 2];
|
||||
|
|
@ -55,6 +58,7 @@ export function findMatchesInText(haystack: string, needle: string): TextMatch[]
|
|||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue