@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue arg0 = args.get(0); SoyValue arg1 = args.get(1); Preconditions.checkArgument( arg0 instanceof StringData || arg0 instanceof SanitizedContent, "First argument to strContains() function is not StringData or SanitizedContent: %s", arg0); String strArg0 = arg0.coerceToString(); String strArg1 = arg1.coerceToString(); return BooleanData.forValue(strArg0.contains(strArg1)); }
@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue arg0 = args.get(0); Preconditions.checkArgument( arg0 instanceof SoyString, "First argument to strLen() function is not StringData or SanitizedContent: %s", arg0); return IntegerData.forValue(arg0.coerceToString().length()); }
public static SoyDict mapToLegacyObjectMap(SoyMap map) { Map<String, SoyValueProvider> keysCoercedToStrings = new HashMap<>(); for (Map.Entry<? extends SoyValue, ? extends SoyValueProvider> entry : map.asJavaMap().entrySet()) { keysCoercedToStrings.put(entry.getKey().coerceToString(), entry.getValue()); } return DictImpl.forProviderMap( keysCoercedToStrings, RuntimeMapTypeTracker.Type.LEGACY_OBJECT_MAP_OR_RECORD); }
/** Makes sure the given input is an instance of either trustedResourceUrl or trustedString. */ public static String filterTrustedResourceUri(SoyValue value) { value = normalizeNull(value); if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI)) { return value.coerceToString(); } logger.log(Level.WARNING, "|filterTrustedResourceUri received bad value ''{0}''", value); return "about:invalid#" + EscapingConventions.INNOCUOUS_OUTPUT; }
/** Converts the input to HTML suitable for use inside {@code <textarea>} by entity escaping. */ public static String escapeHtmlRcdata(SoyValue value) { value = normalizeNull(value); if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.HTML)) { // We can't allow tags in the output, because that would allow safe HTML containing // "<textarea>" to prematurely close the textarea. // Instead, we normalize which is semantics preserving in RCDATA. return normalizeHtml(value.coerceToString()); } return escapeHtml(value.coerceToString()); }
/** Normalizes HTML to HTML making sure quotes and other specials are entity encoded. */ public static String normalizeHtml(SoyValue value) { value = normalizeNull(value); return normalizeHtml(value.coerceToString()); }
/** * 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. */ public static String normalizeHtmlNospace(SoyValue value) { value = normalizeNull(value); return normalizeHtmlNospace(value.coerceToString()); }
/** Makes sure that the given input is a sip URI. */ public static SanitizedContent filterSipUri(SoyValue value) { value = normalizeNull(value); return filterSipUri(value.coerceToString()); }
/** * 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. */ public static String escapeHtmlAttributeNospace(SoyValue value) { value = normalizeNull(value); if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.HTML)) { // |escapeHtmlAttributeNospace should only be used on attribute values that cannot have tags. return stripHtmlTags(value.coerceToString(), null, false); } return escapeHtmlAttributeNospace(value.coerceToString()); }
/** Converts the input to the body of a JavaScript string by using {@code \n} style escapes. */ public static String escapeJsString(SoyValue value) { value = normalizeNull(value); return escapeJsString(value.coerceToString()); }
/** Converts the input to the body of a CSS string literal. */ public static String escapeCssString(SoyValue value) { value = normalizeNull(value); return escapeCssString(value.coerceToString()); }
/** Converts the input to the body of a JavaScript regular expression literal. */ public static String escapeJsRegex(SoyValue value) { value = normalizeNull(value); return escapeJsRegex(value.coerceToString()); }
/** * 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 String normalizeUri(SoyValue value) { value = normalizeNull(value); return normalizeUri(value.coerceToString()); }
/** Checks that the input is part of the name of an innocuous element. */ public static String filterHtmlElementName(SoyValue value) { value = normalizeNull(value); return filterHtmlElementName(value.coerceToString()); }
/** Converts the input to the body of a JavaScript string by using {@code \n} style escapes. */ public static String escapeJsString(SoyValue value) { value = normalizeNull(value); return escapeJsString(value.coerceToString()); }
/** Converts the input to the body of a JavaScript regular expression literal. */ public static String escapeJsRegex(SoyValue value) { value = normalizeNull(value); return escapeJsRegex(value.coerceToString()); }
/** Makes sure that the given input is a tel URI. */ public static SanitizedContent filterTelUri(SoyValue value) { value = normalizeNull(value); return filterTelUri(value.coerceToString()); }
@Override public JavaValue coerceToSoyString() { return TofuJavaValue.forSoyValue( StringData.forValue(soyValue.coerceToString()), sourceLocation); }
public static String bidiMarkAfter(BidiGlobalDir bidiGlobalDir, SoyValue value, boolean isHtml) { Dir valueDir = null; if (value instanceof SanitizedContent) { SanitizedContent sanitizedContent = (SanitizedContent) value; valueDir = sanitizedContent.getContentDirection(); isHtml = isHtml || sanitizedContent.getContentKind() == ContentKind.HTML; } String markAfterKnownDir = BidiFormatter.getInstance(bidiGlobalDir.toDir()) .markAfter(valueDir, value.coerceToString(), isHtml); return markAfterKnownDir; }
public static String bidiMarkAfter(BidiGlobalDir bidiGlobalDir, SoyValue value, boolean isHtml) { Dir valueDir = null; if (value instanceof SanitizedContent) { SanitizedContent sanitizedContent = (SanitizedContent) value; valueDir = sanitizedContent.getContentDirection(); isHtml = isHtml || sanitizedContent.getContentKind() == ContentKind.HTML; } String markAfterKnownDir = BidiFormatter.getInstance(bidiGlobalDir.toDir()) .markAfter(valueDir, value.coerceToString(), isHtml); return markAfterKnownDir; }