Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ng-dev/google-sync-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"src/**/*spec.ts",
"src/cdk/schematics/**/*",
"src/cdk/testing/private/**/*",
"src/cdk/private/inner-html.ts",
"src/material/schematics/**/*",
"src/material/schematics/ng-generate/theme-color/**/*.bazel",
"src/material/schematics/ng-generate/theme-color/index_bundled.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/cdk/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ng_project(
assets = [":visually-hidden-styles"],
deps = [
"//:node_modules/@angular/core",
"//:node_modules/@angular/platform-browser",
],
)

Expand Down
26 changes: 26 additions & 0 deletions src/cdk/private/inner-html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import {SecurityContext} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
import {trustedHTMLFromString} from './trusted-types';

// !!!Note!!! this file isn't synced into g3, but is replaced with a version that uses
// internal-specific APIs. The internal version may have to be updated if the signature of
// the function changes.

/** Sanitizes and sets the `innerHTML` of an element. */
export function _setInnerHtml(element: HTMLElement, html: SafeHtml, sanitizer: DomSanitizer): void {
const cleanHtml = sanitizer.sanitize(SecurityContext.HTML, html);

if (cleanHtml === null && (typeof ngDevMode === 'undefined' || ngDevMode)) {
throw new Error(`Could not sanitize HTML: ${html}`);
}

element.innerHTML = trustedHTMLFromString(cleanHtml || '') as unknown as string;
}
Loading