Package org.unbescape.css
Enum Class CssStringEscapeLevel
- All Implemented Interfaces:
Serializable
,Comparable<CssStringEscapeLevel>
,Constable
Levels defined for escape/unescape operations of CSS strings:
- Level 1: Escape only the basic escape set. Note the result of a level-1 escape
operation might still contain non-ASCII characters if they existed in input, and therefore you
will still need to correctly manage your input/output character encoding settings. Such
basic set consists of:
- The Backslash Escapes:
- The quote symbols: \" (U+0022) and \' (U+0027).
- The backslash: \\ (U+005C).
- The slash (solidus) symbol (/, U+002F), which will be escaped in order to protect from code injection in HTML environments: browsers will parse </style> close tags inside CSS literals and close the tag, therefore allowing for further code injection.
- The ampersand (&, U+0026) and semi-colon (;, U+003B) symbols, which will be escaped in order to protect from code injection in XHTML environments: browsers will parse XHTML escape codes inside literals in <style> tags, therefore allowing the closing of the literal and the <style> tag itself.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- The Backslash Escapes:
- Level 2: Escape the basic escape set (as defined in level 1), plus all non-ASCII characters. The result of a level-2 escape operation is therefore always ASCII-only text, and safer to use in complex scenarios with mixed input/output character encodings.
- Level 3: Escape all non-alphanumeric characters, this is, all but those in the A-Z, a-z and 0-9 ranges. This level can be safely used for completely escaping texts, including whitespace, line feeds, punctuation, etc. in scenarios where this adds an extra level of safety.
- Level 4: Escape all characters, even alphanumeric ones.
For further information, see the Glossary and the References sections at the
documentation for the CssEscape
class.
- Since:
- 1.0.0
- Author:
- Daniel Fernández
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionLevel 1 escape: escape only the basic escape set: Backslash Escape plus non-displayable control chars.Level 2 escape: escape the basic escape set plus all non-ASCII characters (result will always be ASCII).Level 3 escape: escape all non-alphanumeric characteres (escape all but those in the A-Z, a-z and 0-9 ranges).Level 4 escape: escape all characters, including alphanumeric. -
Method Summary
Modifier and TypeMethodDescriptionstatic CssStringEscapeLevel
forLevel
(int level) Utility method for obtaining an enum value from its corresponding int level value.int
Return the int escape level.static CssStringEscapeLevel
Returns the enum constant of this class with the specified name.static CssStringEscapeLevel[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
LEVEL_1_BASIC_ESCAPE_SET
Level 1 escape: escape only the basic escape set: Backslash Escape plus non-displayable control chars. -
LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
Level 2 escape: escape the basic escape set plus all non-ASCII characters (result will always be ASCII). -
LEVEL_3_ALL_NON_ALPHANUMERIC
Level 3 escape: escape all non-alphanumeric characteres (escape all but those in the A-Z, a-z and 0-9 ranges). -
LEVEL_4_ALL_CHARACTERS
Level 4 escape: escape all characters, including alphanumeric.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
forLevel
Utility method for obtaining an enum value from its corresponding int level value.
- Parameters:
level
- the level- Returns:
- the escape level enum constant, or IllegalArgumentException if level does not exist.
-
getEscapeLevel
public int getEscapeLevel()Return the int escape level.- Returns:
- the escape level.
-