diff --git a/packages/core/src/render3/i18n/i18n_parse.ts b/packages/core/src/render3/i18n/i18n_parse.ts index dd79db59cd0..adf333dfc75 100644 --- a/packages/core/src/render3/i18n/i18n_parse.ts +++ b/packages/core/src/render3/i18n/i18n_parse.ts @@ -18,9 +18,9 @@ import { ɵɵsanitizeResourceUrl as _sanitizeResourceUrl, ɵɵsanitizeScript as _sanitizeScript, ɵɵsanitizeStyle as _sanitizeStyle, + ɵɵsanitizeUrl as _sanitizeUrl, ɵɵvalidateAttribute as _validateAttribute, } from '../../sanitization/sanitization'; -import {_sanitizeUrl} from '../../sanitization/url_sanitizer'; import { assertDefined, assertEqual, diff --git a/packages/core/test/acceptance/i18n_spec.ts b/packages/core/test/acceptance/i18n_spec.ts index 352847d90d7..0dd65706d37 100644 --- a/packages/core/test/acceptance/i18n_spec.ts +++ b/packages/core/test/acceptance/i18n_spec.ts @@ -36,6 +36,8 @@ import { PipeTransform, provideZoneChangeDetection, QueryList, + Sanitizer, + SecurityContext, signal, TemplateRef, Type, @@ -3569,6 +3571,45 @@ describe('runtime i18n', () => { expect(link.getAttribute('href')).toMatch(/^unsafe:/); }); + describe('with a custom Sanitizer', () => { + const customSanitizer: Sanitizer = { + sanitize: (context: SecurityContext, value: unknown) => + context === SecurityContext.URL ? `custom:${value}` : String(value), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [{provide: Sanitizer, useValue: customSanitizer}], + }); + }); + + it('should use the custom sanitizer for translated interpolation', () => { + const fixture = initWithTemplate(SanitizeAppComp, ''); + const link: HTMLAnchorElement = fixture.nativeElement.querySelector('a'); + expect(link.getAttribute('href')).toBe('custom:javascript:alert("oh no")'); + }); + + it('should use the custom sanitizer for interpolation inside translated element', () => { + const fixture = initWithTemplate(SanitizeAppComp, `
`); + const link: HTMLAnchorElement = fixture.nativeElement.querySelector('a'); + expect(link.getAttribute('href')).toBe('custom:javascript:alert("oh no")'); + }); + + it('should use the custom sanitizer for interpolation inside an ICU', () => { + const fixture = initWithTemplate( + SanitizeAppComp, + `