public abstract static class EscapingConventions.CrossLanguageStringXform extends Object implements Escaper
1 < 2 can be escaped to the equivalent HTML string
1 < 2.http://www.google.com/search?q=O'Reilly is equivalent to
http://www.google.com/search?q=O%27Reilly but the latter can be safely
embedded in a single quoted HTML attribute.h1 might pass an html identifier filter but the string
><script>alert('evil')</script> should not and could be replaced by an innocuous
value like zzz.| Modifier | Constructor and Description |
|---|---|
protected |
CrossLanguageStringXform(Pattern valueFilter,
String nonAsciiPrefix) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract com.google.common.collect.ImmutableList<EscapingConventions.Escape> |
defineEscapes()
Returns the escapes used for this escaper.
|
Appendable |
escape(Appendable out)
Returns an
Appendable instance which automatically escapes all
text appended to it before passing the resulting text to an underlying
Appendable. |
String |
escape(String string)
Returns the escaped form of a given literal string.
|
String |
getDirectiveName()
The name of the directive associated with this escaping function.
|
com.google.common.collect.ImmutableList<EscapingConventions.Escape> |
getEscapes()
The escapes need to translate the input language to the output language.
|
String |
getInnocuousOutput()
Returns an innocuous string in this context that can be used when filtering.
|
List<String> |
getLangFunctionNames(EscapingConventions.EscapingLanguage language)
The names of existing language builtins or available library functions (such as Google
Closure) that implement the escaping convention.
|
String |
getNonAsciiPrefix()
An escaping prefix in
"%", "\\u", "\\" which specifies how to escape non-ASCII code
units not in the sparse mapping. |
Pattern |
getValueFilter()
Null if the escaper accepts all strings as inputs, or otherwise a regular expression
that accepts only strings that can be escaped by this escaper.
|
protected CrossLanguageStringXform(@Nullable Pattern valueFilter, @Nullable String nonAsciiPrefix)
valueFilter - null if the directive accepts all strings as inputs. Otherwise
a regular expression that accepts only strings that can be escaped by this directive.nonAsciiPrefix - An escaping prefix in "%", "\\u", "\\" which specifies how to
escape non-ASCII code units not in the sparse mapping.
If null, then non-ASCII code units outside the sparse map can appear unescaped.protected abstract com.google.common.collect.ImmutableList<EscapingConventions.Escape> defineEscapes()
public String getDirectiveName()
|escapeHtml@Nullable public final String getNonAsciiPrefix()
"%", "\\u", "\\" which specifies how to escape non-ASCII code
units not in the sparse mapping.
If null, then non-ASCII code units outside the sparse map can appear unescaped.@Nullable public final Pattern getValueFilter()
public final com.google.common.collect.ImmutableList<EscapingConventions.Escape> getEscapes()
public List<String> getLangFunctionNames(EscapingConventions.EscapingLanguage language)
language - The language being escaped.null if there is no such function.public String getInnocuousOutput()
public final String escape(String string)
EscaperNote that this method may treat input characters differently depending on the specific escaper implementation.
UnicodeEscaper handles
UTF-16 correctly,
including surrogate character pairs. If the input is badly formed the
escaper should throw IllegalArgumentException.
CharEscaper handles Java characters independently and does not
verify the input for well formed characters. A CharEscaper should not be
used in situations where input is not guaranteed to be restricted to the
Basic Multilingual Plane (BMP).
public final Appendable escape(Appendable out)
EscaperAppendable instance which automatically escapes all
text appended to it before passing the resulting text to an underlying
Appendable.
Note that the Appendable returned by this method may treat input characters differently depending on the specific escaper implementation.
UnicodeEscaper handles
UTF-16 correctly,
including surrogate character pairs. If the input is badly formed the
escaper should throw IllegalArgumentException.
CharEscaper handles Java characters independently and does not
verify the input for well formed characters. A CharEscaper should not be
used in situations where input is not guaranteed to be restricted to the
Basic Multilingual Plane (BMP).
In all implementations the escaped Appendable should throw
NullPointerException if given a null CharSequence.