public final class Sanitizers extends Object
soy.$$escape*,
soy.$$normalize*, and soy.$$filter* functions defined in "soyutils.js".| Modifier and Type | Field and Description |
|---|---|
static Pattern |
HTML_ATTRIBUTE_PATTERN
Pattern for matching attribute name and value, where value is single-quoted or double-quoted.
|
| Modifier and Type | Method and Description |
|---|---|
static SoyValue |
blessStringAsTrustedResourceUrlForLegacy(SoyValue value)
For any resource string/variable which has |blessStringAsTrustedResuorceUrlForLegacy directive
return the input value as is.
|
static SoyValue |
blessStringAsTrustedResourceUrlForLegacy(String value)
For any resource string/variable which has |blessStringAsTrustedResuorceUrlForLegacy directive
return the input value as is after converting it into SoyValue.
|
static LoggingAdvisingAppendable |
blessStringAsTrustedResourceUrlForLegacyStreaming(LoggingAdvisingAppendable appendable)
For any resource string/variable which has |blessStringAsTrustedResuorceUrlForLegacy directive
apply a no-op escaping directive
|
static SanitizedContent |
cleanHtml(SoyValue value)
Normalizes the input HTML while preserving "safe" tags and the known directionality.
|
static SanitizedContent |
cleanHtml(SoyValue value,
Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
Normalizes the input HTML while preserving "safe" tags and the known directionality.
|
static SanitizedContent |
cleanHtml(String value)
Normalizes the input HTML while preserving "safe" tags.
|
static SanitizedContent |
cleanHtml(String value,
Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
Normalizes the input HTML while preserving "safe" tags.
|
static SanitizedContent |
cleanHtml(String value,
Dir contentDir,
Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
Normalizes the input HTML of a given directionality while preserving "safe" tags.
|
static LoggingAdvisingAppendable |
cleanHtmlStreaming(LoggingAdvisingAppendable delegate,
Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
Streaming version of
|cleanHtml. |
static String |
escapeCssString(SoyValue value)
Converts the input to the body of a CSS string literal.
|
static String |
escapeCssString(String value)
Converts plain text to the body of a CSS string literal.
|
static LoggingAdvisingAppendable |
escapeCssStringStreaming(LoggingAdvisingAppendable delegate)
Converts the input to the body of a CSS string literal.
|
static String |
escapeHtml(SoyValue value)
Converts the input to HTML by entity escaping.
|
static String |
escapeHtml(String value)
Converts plain text to HTML by entity escaping.
|
static String |
escapeHtmlAttribute(SoyValue value)
Converts the input to HTML by entity escaping, stripping tags in sanitized content so the
result can safely be embedded in an HTML attribute value.
|
static String |
escapeHtmlAttribute(String value)
Converts plain text to HTML by entity escaping so the result can safely be embedded in an HTML
attribute value.
|
static String |
escapeHtmlAttributeNospace(SoyValue value)
Converts plain text to HTML by entity escaping, stripping tags in sanitized content so the
result can safely be embedded in an unquoted HTML attribute value.
|
static String |
escapeHtmlAttributeNospace(String value)
Converts plain text to HTML by entity escaping so the result can safely be embedded in an
unquoted HTML attribute value.
|
static String |
escapeHtmlRcdata(SoyValue value)
Converts the input to HTML suitable for use inside
<textarea> by entity escaping. |
static LoggingAdvisingAppendable |
escapeHtmlRcdataStreaming(LoggingAdvisingAppendable delegate)
Streaming version of
|escapeHtmlRcData. |
static String |
escapeJsRegex(SoyValue value)
Converts the input to the body of a JavaScript regular expression literal.
|
static String |
escapeJsRegex(String value)
Converts plain text to the body of a JavaScript regular expression literal.
|
static LoggingAdvisingAppendable |
escapeJsRegexStreaming(LoggingAdvisingAppendable delegate)
Converts the input to the body of a JavaScript regular expression literal.
|
static String |
escapeJsString(SoyValue value)
Converts the input to the body of a JavaScript string by using
\n style escapes. |
static String |
escapeJsString(String value)
Converts plain text to the body of a JavaScript string by using
\n style escapes. |
static LoggingAdvisingAppendable |
escapeJsStringStreaming(LoggingAdvisingAppendable appendable) |
static String |
escapeJsValue(SoyValue value)
Converts the input to a JavaScript expression.
|
static String |
escapeJsValue(String value)
Converts plain text to a quoted javaScript string value.
|
static String |
escapeUri(SoyValue value)
Converts the input to a piece of a URI by percent encoding the value as UTF-8 bytes.
|
static String |
escapeUri(String value)
Converts plain text to a piece of a URI by percent encoding the string as UTF-8 bytes.
|
static String |
filterCssValue(SoyValue value)
Makes sure that the input is a valid CSS identifier part, CLASS or ID part, quantity, or CSS
keyword part.
|
static String |
filterCssValue(String value)
Makes sure that the input is a valid CSS identifier part, CLASS or ID part, quantity, or CSS
keyword part.
|
static String |
filterHtmlAttributes(SoyValue value)
Checks that the input is a valid HTML attribute name with normal keyword or textual content or
known safe attribute content.
|
static String |
filterHtmlAttributes(String value)
Checks that the input is a valid HTML attribute name with normal keyword or textual content.
|
static LoggingAdvisingAppendable |
filterHtmlAttributesStreaming(LoggingAdvisingAppendable appendable) |
static String |
filterHtmlElementName(SoyValue value)
Checks that the input is part of the name of an innocuous element.
|
static String |
filterHtmlElementName(String value)
Checks that the input is part of the name of an innocuous element.
|
static SanitizedContent |
filterImageDataUri(SoyValue value)
Makes sure that the given input is a data URI corresponding to an image.
|
static SanitizedContent |
filterImageDataUri(String value)
Makes sure that the given input is a data URI corresponding to an image.
|
static SoyValue |
filterNoAutoescape(SoyValue value)
Filters noAutoescape input from explicitly tainted content.
|
static LoggingAdvisingAppendable |
filterNoAutoescapeStreaming(LoggingAdvisingAppendable appendable)
Applies the |noAutoescape directive and filters explicitly tainted content.
|
static String |
filterNormalizeMediaUri(SoyValue value)
Checks that a URI is safe to be an image source.
|
static String |
filterNormalizeMediaUri(String value)
Checks that a URI is safe to be an image source.
|
static String |
filterNormalizeUri(SoyValue value)
Makes sure that the given input doesn't specify a dangerous protocol and also
normalizes it. |
static String |
filterNormalizeUri(String value)
Makes sure that the given input doesn't specify a dangerous protocol and also
normalizes it. |
static SanitizedContent |
filterSipUri(SoyValue value)
Makes sure that the given input is a sip URI.
|
static SanitizedContent |
filterSipUri(String value)
Makes sure that the given input is a sip URI.
|
static SanitizedContent |
filterTelUri(SoyValue value)
Makes sure that the given input is a tel URI.
|
static SanitizedContent |
filterTelUri(String value)
Makes sure that the given input is a tel URI.
|
static String |
filterTrustedResourceUri(SoyValue value)
Makes sure the given input is an instance of either trustedResourceUrl or trustedString.
|
static String |
filterTrustedResourceUri(String value)
For string inputs this function just returns the input string itself.
|
static String |
normalizeHtml(SoyValue value)
Normalizes HTML to HTML making sure quotes and other specials are entity encoded.
|
static String |
normalizeHtml(String value)
Normalizes HTML to HTML making sure quotes and other specials are entity encoded.
|
static String |
normalizeHtmlNospace(SoyValue value)
Normalizes HTML to HTML making sure quotes, spaces and other specials are entity encoded so
that the result can be safely embedded in a valueless attribute.
|
static String |
normalizeHtmlNospace(String value)
Normalizes HTML to HTML making sure quotes, spaces and other specials are entity encoded so
that the result can be safely embedded in a valueless attribute.
|
static LoggingAdvisingAppendable |
normalizeHtmlStreaming(LoggingAdvisingAppendable appendable) |
static String |
normalizeUri(SoyValue value)
Converts a piece of URI content to a piece of URI content that can be safely embedded in an
HTML attribute by percent encoding.
|
static String |
normalizeUri(String value)
Converts a piece of URI content to a piece of URI content that can be safely embedded in an
HTML attribute by percent encoding.
|
static LoggingAdvisingAppendable |
normalizeUriStreaming(LoggingAdvisingAppendable value)
Converts a piece of URI content to a piece of URI content that can be safely embedded in an
HTML attribute by percent encoding.
|
public static final Pattern HTML_ATTRIBUTE_PATTERN
public static String escapeHtml(SoyValue value)
public static String escapeHtml(String value)
public static SanitizedContent cleanHtml(SoyValue value)
SanitizedContent of SanitizedContent.ContentKind.HTMLpublic static SanitizedContent cleanHtml(SoyValue value, Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
optionalSafeTags - to add to the basic whitelist of formatting safe tagsSanitizedContent of SanitizedContent.ContentKind.HTMLpublic static LoggingAdvisingAppendable cleanHtmlStreaming(LoggingAdvisingAppendable delegate, Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
|cleanHtml.public static SanitizedContent cleanHtml(String value)
SanitizedContent of SanitizedContent.ContentKind.HTMLpublic static SanitizedContent cleanHtml(String value, Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
optionalSafeTags - to add to the basic whitelist of formatting safe tagsSanitizedContent of SanitizedContent.ContentKind.HTMLpublic static SanitizedContent cleanHtml(String value, Dir contentDir, Collection<? extends TagWhitelist.OptionalSafeTag> optionalSafeTags)
optionalSafeTags - to add to the basic whitelist of formatting safe tagsSanitizedContent of SanitizedContent.ContentKind.HTMLpublic static String escapeHtmlRcdata(SoyValue value)
<textarea> by entity escaping.public static LoggingAdvisingAppendable escapeHtmlRcdataStreaming(LoggingAdvisingAppendable delegate)
|escapeHtmlRcData.public static String normalizeHtml(SoyValue value)
public static LoggingAdvisingAppendable normalizeHtmlStreaming(LoggingAdvisingAppendable appendable)
public static String normalizeHtml(String value)
public static String normalizeHtmlNospace(SoyValue value)
public static String normalizeHtmlNospace(String value)
public static String escapeHtmlAttribute(SoyValue value)
public static String escapeHtmlAttribute(String value)
public static String escapeHtmlAttributeNospace(SoyValue value)
public static String escapeHtmlAttributeNospace(String value)
public static String escapeJsString(SoyValue value)
\n style escapes.public static LoggingAdvisingAppendable escapeJsStringStreaming(LoggingAdvisingAppendable appendable)
public static String escapeJsString(String value)
\n style escapes.public static String escapeJsValue(SoyValue value)
null.public static String escapeJsValue(String value)
public static String escapeJsRegex(SoyValue value)
public static LoggingAdvisingAppendable escapeJsRegexStreaming(LoggingAdvisingAppendable delegate)
public static String escapeJsRegex(String value)
public static String escapeCssString(SoyValue value)
public static LoggingAdvisingAppendable escapeCssStringStreaming(LoggingAdvisingAppendable delegate)
public static String escapeCssString(String value)
public static String filterCssValue(SoyValue value)
public static String filterCssValue(String value)
public static String escapeUri(SoyValue value)
public static String escapeUri(String value)
public static String normalizeUri(SoyValue value)
public static LoggingAdvisingAppendable normalizeUriStreaming(LoggingAdvisingAppendable value)
public static String normalizeUri(String value)
public static String filterNormalizeUri(SoyValue value)
normalizes it.public static String filterNormalizeUri(String value)
normalizes it.public static String filterNormalizeMediaUri(SoyValue value)
Does not return SanitizedContent as there isn't an appropriate type for this.
public static String filterNormalizeMediaUri(String value)
Does not return SanitizedContent as there isn't an appropriate type for this.
public static String filterTrustedResourceUri(SoyValue value)
public static String filterTrustedResourceUri(String value)
public static SoyValue blessStringAsTrustedResourceUrlForLegacy(SoyValue value)
public static SoyValue blessStringAsTrustedResourceUrlForLegacy(String value)
public static LoggingAdvisingAppendable blessStringAsTrustedResourceUrlForLegacyStreaming(LoggingAdvisingAppendable appendable)
public static SanitizedContent filterImageDataUri(SoyValue value)
SanitizedContent kind does not apply -- the directive is also used to ensure no foreign resources are loaded.
public static SanitizedContent filterImageDataUri(String value)
public static SanitizedContent filterSipUri(SoyValue value)
public static SanitizedContent filterSipUri(String value)
public static SanitizedContent filterTelUri(SoyValue value)
public static SanitizedContent filterTelUri(String value)
public static String filterHtmlAttributes(SoyValue value)
public static String filterHtmlAttributes(String value)
public static LoggingAdvisingAppendable filterHtmlAttributesStreaming(LoggingAdvisingAppendable appendable)
public static String filterHtmlElementName(SoyValue value)
public static String filterHtmlElementName(String value)
public static SoyValue filterNoAutoescape(SoyValue value)
SanitizedContent.ContentKind.TEXT is used to explicitly mark input that is never meant to be used unescaped. Specifically, {let} and {param} blocks of kind "text" are explicitly forbidden from being noAutoescaped to avoid XSS regressions during application transition.
public static LoggingAdvisingAppendable filterNoAutoescapeStreaming(LoggingAdvisingAppendable appendable)