Package org.owasp.encoder
Class HTMLEncoder
- java.lang.Object
-
- org.owasp.encoder.Encoder
-
- org.owasp.encoder.HTMLEncoder
-
class HTMLEncoder extends Encoder
HTMLEncoder -- an encoder for HTML contexts. Currently most HTML-based contexts are properly handled by
XMLEncoder
. The remaining HTML-specific context of "unquoted attributes" could not be added to the XMLEncoder without slowing it down. This class implements that remaining context: unquoted attribute values.Note: because this context is likely small strings, and hopefully rarely used, no effort was put into optimizing this encoder.
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]
AMP
Encoding for '&'.private static int
ENCODE_AFFIX_CHAR_COUNT
Number of characters in the encoding prefix and suffix when using decimal numeric encodings of the form "...;".private static char[]
GT
Encoding for '>'.private static char[]
LT
Encoding for '<'.private static char[]
TAB
Encoding for '\t'.
-
Constructor Summary
Constructors Constructor Description HTMLEncoder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static int
append(char[] src, char[] out, int j)
Appends a source array verbatim to the output array.(package private) static int
encode(int codePoint, char[] out, int j)
Appends the numerically encoded version ofcodePoint
to the output buffer.(package private) java.nio.charset.CoderResult
encodeArrays(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
The core encoding loop used when both the input and output buffers are array backed.(package private) int
firstEncodedOffset(java.lang.String input, int off, int len)
Scans the input string for the first character index that requires encoding.(package private) int
maxEncodedLength(int n)
Returns the maximum encoded length (in chars) of an input sequence ofn
characters.-
Methods inherited from class org.owasp.encoder.Encoder
encode, encodeBuffers, overflow, underflow
-
-
-
-
Field Detail
-
ENCODE_AFFIX_CHAR_COUNT
private static final int ENCODE_AFFIX_CHAR_COUNT
Number of characters in the encoding prefix and suffix when using decimal numeric encodings of the form "...;".- See Also:
- Constant Field Values
-
TAB
private static final char[] TAB
Encoding for '\t'.
-
AMP
private static final char[] AMP
Encoding for '&'.
-
LT
private static final char[] LT
Encoding for '<'.
-
GT
private static final char[] GT
Encoding for '>'.
-
-
Method Detail
-
maxEncodedLength
int maxEncodedLength(int n)
Description copied from class:Encoder
Returns the maximum encoded length (in chars) of an input sequence ofn
characters.- Specified by:
maxEncodedLength
in classEncoder
- Parameters:
n
- the number of characters of input- Returns:
- the worst-case number of characters required to encode
-
firstEncodedOffset
int firstEncodedOffset(java.lang.String input, int off, int len)
Description copied from class:Encoder
Scans the input string for the first character index that requires encoding. If the entire input does not require encoding then the length is returned. This method is used by the Encode.forXYZ methods to return input strings unchanged when possible.- Specified by:
firstEncodedOffset
in classEncoder
- Parameters:
input
- the input to check for encodingoff
- the offset of the first character to checklen
- the number of characters to check- Returns:
- the index of the first character to encode. The return value
will be
off+len
if no characters in the input require encoding.
-
append
static int append(char[] src, char[] out, int j)
Appends a source array verbatim to the output array. Caller must insure there is enough space in the array for the output.- Parameters:
src
- the characters to copyout
- the output bufferj
- the offset where to write in the output buffer- Returns:
j + src.length
-
encode
static int encode(int codePoint, char[] out, int j)
Appends the numerically encoded version ofcodePoint
to the output buffer. Caller must insure there is enough space for the output.- Parameters:
codePoint
- the character to encodeout
- the output bufferj
- the offset where to write in the output buffer- Returns:
j
+ the encoded length.
-
encodeArrays
java.nio.charset.CoderResult encodeArrays(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
Description copied from class:Encoder
The core encoding loop used when both the input and output buffers are array backed. The loop is expected to fetch the arrays and interact with the arrays directly for performance.- Overrides:
encodeArrays
in classEncoder
- Parameters:
input
- the input buffer.output
- the output buffer.endOfInput
- when true, this is the last input to encode- Returns:
- UNDERFLOW or OVERFLOW
-
-