public final class XSS extends Object
Modifier and Type | Method and Description |
---|---|
static String |
html(String value)
Perform an HTML5 level 2 (result is ASCII) escape operation on a String input.
|
static String |
javaScript(String value)
Perform a JavaScript level 2 (basic set and all non-ASCII chars) escape operation
on a String input.
|
static String |
json(String value)
Perform a JSON level 2 (basic set and all non-ASCII chars) escape operation
on a String input.
|
static String |
uri(String value)
Perform am URI path escape operation
on a String input using UTF-8 as encoding.
|
static String |
xml(String value)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation
on a String input.
|
@Nullable public static String uri(@Nullable String value)
Perform am URI path escape operation on a String input using UTF-8 as encoding.
The following are the only allowed chars in an URI path (will not be escaped):
All other chars will be escaped by converting them to the sequence of bytes that represents them in the UTF-8 and then representing each byte in %HH syntax, being HH the hexadecimal representation of the byte.
This method is thread-safe.
value
- the String to be escaped.@Nullable public static String html(@Nullable String value)
Perform an HTML5 level 2 (result is ASCII) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by replacing those chars by the corresponding HTML5 Named Character References (e.g. '´') when such NCR exists for the replaced character, and replacing by a decimal character reference (e.g. 'ₙ') when there there is no NCR for the replaced character.
This method is thread-safe.
value
- the String to be escaped.@Nullable public static String javaScript(@Nullable String value)
Perform a JavaScript level 2 (basic set and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by using the Single Escape Chars whenever possible. For escaped characters that do not have an associated SEC, default to using \xFF Hexadecimal Escapes if possible (characters <= U+00FF), then default to \uFFFF Hexadecimal Escapes. This type of escape produces the smallest escaped string possible.
This method is thread-safe.
value
- the String to be escaped.@Nullable public static String json(@Nullable String value)
Perform a JSON level 2 (basic set and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by using the Single Escape Chars whenever possible. For escaped characters that do not have an associated SEC, default to \uFFFF Hexadecimal Escapes.
This method is thread-safe.
value
- the String to be escaped.@Nullable public static String xml(@Nullable String value)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method is thread-safe.
value
- the String to be escaped.Copyright © 2020. All rights reserved.