angular/aio/src/app/shared/security.ts
Bjarki 2b267209a1 fix(docs-infra): make custom icon registry compatible with Trusted Types (#42800)
Change SvgIconInfo.svgSource to be a TrustedHTML and update all its
users accordingly. Also introduce the svg template tag function for
building TrustedHTML from constant SVG sources.

PR Close #42800
2021-09-09 11:16:59 -07:00

17 lines
718 B
TypeScript

import { htmlFromStringKnownToSatisfyTypeContract } from 'safevalues/unsafe/reviewed';
export function fromInnerHTML(el: Element): TrustedHTML {
// SECURITY: Existing innerHTML content is already trusted.
return htmlFromStringKnownToSatisfyTypeContract(el.innerHTML, '^');
}
export function fromOuterHTML(el: Element): TrustedHTML {
// SECURITY: Existing outerHTML content is already trusted.
return htmlFromStringKnownToSatisfyTypeContract(el.outerHTML, '^');
}
export function svg(constantSvg: TemplateStringsArray): TrustedHTML {
// SECURITY: Template literal argument with no interpolation is constant, and
// hence trusted.
return htmlFromStringKnownToSatisfyTypeContract(constantSvg[0], '^');
}