Skip to content
Snippets Groups Projects
Unverified Commit 6af2be72 authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(templates): use re2 for replace helper (#26019)

parent 8c78b5a7
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,15 @@ describe('util/template/index', () => {
expect(output).toBe('CUSTOM_FOO is foo');
});
it('replace', () => {
const userTemplate =
"{{ replace '[a-z]+\\.github\\.com' 'ghc' depName }}{{ replace 'some' 'other' depType }}";
const output = template.compile(userTemplate, {
depName: 'some.github.com/dep',
});
expect(output).toBe('ghc/dep');
});
describe('proxyCompileInput', () => {
const allowedField = 'body';
const allowedArrayField = 'prBodyNotes';
......
......@@ -3,6 +3,7 @@ import handlebars from 'handlebars';
import { GlobalConfig } from '../../config/global';
import { logger } from '../../logger';
import { getChildEnv } from '../exec/utils';
import { regEx } from '../regex';
handlebars.registerHelper('encodeURIComponent', encodeURIComponent);
handlebars.registerHelper('decodeURIComponent', decodeURIComponent);
......@@ -11,11 +12,8 @@ handlebars.registerHelper('stringToPrettyJSON', (input: string): string =>
JSON.stringify(JSON.parse(input), null, 2),
);
// istanbul ignore next
handlebars.registerHelper(
'replace',
(find, replace, context) =>
(context || '').replace(new RegExp(find, 'g'), replace), // TODO #12873
handlebars.registerHelper('replace', (find, replace, context) =>
(context ?? '').replace(regEx(find, 'g'), replace),
);
handlebars.registerHelper('lowercase', (str: string) => str?.toLowerCase());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment