mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
Binding `null` or `undefined` to a resource URL property such as
`<iframe [src]>` throws NG0904 ("unsafe value used in a resource URL
context"), even though there is nothing unsafe about clearing the binding.
The inlined `ɵɵsanitizeResourceUrl` only accepts values marked trusted with
`bypassSecurityTrustResourceUrl` and rejects everything else, including
nullish values. This forces users to bind a trusted placeholder such as
`about:blank` instead of simply using `undefined`.
The same binding already works when a custom `Sanitizer` is provided,
because `DomSanitizer.sanitize` returns `null` for nullish values, which is
then mapped to an empty string. Apply the same handling to the inlined
sanitizer: `null` and `undefined` are mapped to an empty string, which the
browser treats as `about:blank` for `<iframe src>`. Since
`setElementAttribute` runs the sanitizer before removing an attribute for a
nullish value, this also fixes `[attr.src]` bindings on resource URL
attributes.
Fixes #42527