public final class HTMLEncoder extends Object
org.owasp.esapi.Encoder
,
org.owasp.esapi.reference.DefaultEncoder
,
org.owasp.esapi.codecs.HTMLEntityCodec
Modifier and Type | Field and Description |
---|---|
private static Map<Character,String> |
CHARACTER_TO_ENTITY_MAP
Map from entity character to name.
|
private static String[] |
HEX
Initialize an array to mark which characters are to be encoded.
|
static char[] |
IMMUNE_HTML
Character set immune from HTML encoding.
|
static char[] |
IMMUNE_HTMLATTR
Character set immune from HTML attribute encoding.
|
static char |
REPLACEMENT_CHAR
Character to replace illegal characters.
|
static String |
REPLACEMENT_HEX
Hex to replace illegal characters.
|
Modifier | Constructor and Description |
---|---|
private |
HTMLEncoder()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private static boolean |
containsCharacter(char c,
char[] array)
Utility to search a char[] for a specific char.
|
private static String |
encode(char[] immune,
String input)
Encode a string for safe use in an HTML entity field.
|
private static String |
encodeCharacter(char[] immune,
Character toEncode)
Encodes a character for safe use in an HTML entity field.
|
static String |
encodeForHTML(String input)
Encode data for use in HTML using HTML entity encoding
|
static String |
encodeForHTMLAttribute(String input)
Encode data for use in HTML attributes.
|
private static String |
getHexForNonAlphanumeric(char c)
Lookup the hex value of any character that is not alphanumeric.
|
private static Map<Character,String> |
mkCharacterToEntityMap()
Build an unmodifiable map from entity character to name.
|
@Nonnull public static final char[] IMMUNE_HTML
@Nonnull public static final char[] IMMUNE_HTMLATTR
@Nonnull public static final char REPLACEMENT_CHAR
@Nonnull public static final String REPLACEMENT_HEX
@Nonnull private static final Map<Character,String> CHARACTER_TO_ENTITY_MAP
@Nullable public static String encodeForHTML(@Nullable String input)
Note that the following characters: 00-08, 0B-0C, 0E-1F, and 7F-9F
cannot be used in HTML.
input
- the text to encode for HTML@Nullable public static String encodeForHTMLAttribute(@Nullable String input)
input
- the text to encode for an HTML attribute@Nonnull private static String encode(@Nonnull char[] immune, @Nonnull String input)
immune
- characters immune from encodinginput
- the string to encode@Nonnull private static String encodeCharacter(@Nonnull char[] immune, @Nonnull Character toEncode)
immune
- characters immune from encodingtoEncode
- the character to encode@Nonnull private static String getHexForNonAlphanumeric(@Nonnull char c)
c
- the character to lookup.private static boolean containsCharacter(@Nonnull char c, @Nonnull char[] array)
c
- the chararray
- the arrayCopyright © 1999–2019 Shibboleth Consortium. All rights reserved.