search

goog.html.SafeHtml

Module ID
All Implemented Interfaces

A string that is safe to use in HTML context in DOM APIs and HTML documents.

A SafeHtml is a string-like object that carries the security type contract that its value as a string will not cause untrusted script execution when evaluated as HTML in a browser.

Values of this type are guaranteed to be safe to use in HTML contexts, such as, assignment to the innerHTML DOM property, or interpolation into a HTML template in HTML PC_DATA context, in the sense that the use will not result in a Cross-Site-Scripting vulnerability.

Instances of this type must be created via the factory methods (SafeHtml.create, SafeHtml.htmlEscape), etc and not by invoking its constructor. The constructor intentionally takes an extra parameter that cannot be constructed outside of this file and the type is immutable; hence only a default instance corresponding to the empty string can be obtained via constructor invocation.

Creating SafeHtml objects HAS SIDE-EFFECTS due to calling Trusted Types Web API.

Note that there is no SafeHtml.fromConstant. The reason is that the following code would create an unsafe HTML:

SafeHtml.concat(
    SafeHtml.fromConstant(Const.from('<script>')),
    SafeHtml.htmlEscape(userInput),
    SafeHtml.fromConstant(Const.from('<\/script>')));

There's goog.dom.constHtmlToNode to create a node from constant strings only.

new SafeHtml( arg0, arg1 )

Parameters
arg0(TrustedHTML|string)
arg1Object
See Also

SafeHtml.create

SafeHtml.htmlEscape

Instance Methods

Instance Properties

Exported Functions

Exported Properties

Compiler Constants