From 7c883e02bdde46041b729906fec537ea4e57636b Mon Sep 17 00:00:00 2001 From: aparziale Date: Sat, 31 Oct 2026 10:57:54 +0100 Subject: [PATCH] fix(core): allow binding null and undefined to resource URL properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binding `null` or `undefined` to a resource URL property such as ``; + TestBed.overrideComponent(SecuredComponent, {set: {template}}); + const fixture = TestBed.createComponent(SecuredComponent); + + // The property is set to an empty string, which the browser treats as `about:blank`. + checkNullishResourceUrl(fixture, ''); + }); + + it('should allow binding null and undefined to resource URL attributes', () => { + const template = ``; + TestBed.overrideComponent(SecuredComponent, {set: {template}}); + const fixture = TestBed.createComponent(SecuredComponent); + + // Nullish attribute values remove the attribute without going through the sanitizer. + checkNullishResourceUrl(fixture, null); + }); + it('should escape unsafe attributes', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); diff --git a/packages/core/test/sanitization/sanitization_spec.ts b/packages/core/test/sanitization/sanitization_spec.ts index c8d794fe4d8..0a5880256a8 100644 --- a/packages/core/test/sanitization/sanitization_spec.ts +++ b/packages/core/test/sanitization/sanitization_spec.ts @@ -91,6 +91,11 @@ describe('sanitization', () => { ).toEqual('javascript:true'); }); + it('should map null and undefined resourceUrls to an empty string', () => { + expect(ɵɵsanitizeResourceUrl(null).toString()).toEqual(''); + expect(ɵɵsanitizeResourceUrl(undefined).toString()).toEqual(''); + }); + it('should sanitize style', () => { expect(ɵɵsanitizeStyle('red')).toEqual('red'); expect(ɵɵsanitizeStyle(new Wrap('red'))).toEqual('red');