mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(templates): add decodeURIComponent helper (#19616)
This commit is contained in:
parent
f2a8699277
commit
aecfcdbb3c
3 changed files with 29 additions and 0 deletions
|
@ -49,6 +49,16 @@ In the example above `baseDir` is the string you want to transform into a valid
|
|||
|
||||
Read the [MDN Web Docs, encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) to learn more.
|
||||
|
||||
### decodeURIComponent
|
||||
|
||||
If you want to decode a percent-encoded string, use the built-in function `decodeURIComponent` like this:
|
||||
|
||||
`{{{decodeURIComponent depName}}}`
|
||||
|
||||
In the example above `depName` is the string you want to decode.
|
||||
|
||||
Read the [MDN Web Docs, decodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent) to learn more.
|
||||
|
||||
### replace
|
||||
|
||||
The `replace` helper replaces _all_ found strings with the replacement string.
|
||||
|
|
|
@ -158,4 +158,22 @@ describe('util/template/index', () => {
|
|||
expect(template.containsTemplates('{{body}}', ['logJSON'])).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('percent encoding', () => {
|
||||
it('encodes values', () => {
|
||||
const output = template.compile(
|
||||
'{{{encodeURIComponent "@fsouza/prettierd"}}}',
|
||||
undefined as never
|
||||
);
|
||||
expect(output).toBe('%40fsouza%2Fprettierd');
|
||||
});
|
||||
|
||||
it('decodes values', () => {
|
||||
const output = template.compile(
|
||||
'{{{decodeURIComponent "%40fsouza/prettierd"}}}',
|
||||
undefined as never
|
||||
);
|
||||
expect(output).toBe('@fsouza/prettierd');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import { GlobalConfig } from '../../config/global';
|
|||
import { logger } from '../../logger';
|
||||
|
||||
handlebars.registerHelper('encodeURIComponent', encodeURIComponent);
|
||||
handlebars.registerHelper('decodeURIComponent', decodeURIComponent);
|
||||
|
||||
handlebars.registerHelper('stringToPrettyJSON', (input: string): string =>
|
||||
JSON.stringify(JSON.parse(input), null, 2)
|
||||
|
|
Loading…
Reference in a new issue