1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-08 12:40:26 +00:00

Escape any potential <0></0> tags from i18n arguments

This commit is contained in:
Shane
2025-07-25 12:44:22 -07:00
parent e30b39d807
commit 0fa039a7e0

View File

@@ -59,10 +59,26 @@ export class I18nComponent {
*/
args = input<(string | number)[]>([]);
/**
* Escapes any <0></0> like tags that may be present in the arguments to
* prevent breaking the template rendering.
*/
escapeArgs(args: (string | number)[]): (string | number)[] {
return args.map((arg) => {
if (typeof arg === "string") {
return arg.replace(/<\/?\d+>/g, (tag) => tag.replace(/</g, "&lt;").replace(/>/g, "&gt;"));
}
return arg.toString();
});
}
private tagTemplates = contentChildren(I18nPartDirective, { read: TemplateRef });
private translatedText = computed(() => {
const translatedText = this.i18nService.t(this.translationKey(), ...this.args());
const translatedText = this.i18nService.t(
this.translationKey(),
...this.escapeArgs(this.args()),
);
return this.parseTranslatedString(translatedText);
});