Package org.owasp.encoder
Class CSSEncoder
- java.lang.Object
-
- org.owasp.encoder.Encoder
-
- org.owasp.encoder.CSSEncoder
-
class CSSEncoder extends Encoder
CSSEncoder -- Encoder for Cascading-Style-Sheet string and URI contexts. Other contexts, such as color, number (w/unit), etc... are not good targets for "encoding" (e.g. you cannot encode the string "XYZ" into a number), they should instead by validated through other means (such as regular expressions).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classCSSEncoder.ModeEncoding mode of operation--specified the set of characters that required encoding.
-
Field Summary
Fields Modifier and Type Field Description (package private) long_highMaskThe bit-mask of unescaped characters in the range 64 to 127.(package private) long_lowMaskThe bit-mask of unescaped characters in the range 0 to 63.(package private) CSSEncoder.Mode_modeThe mode of operation, used primarily for toString.(package private) static intHEX_ENCODED_LENGTHLength of hex encoding with trailing space"\## ".(package private) static charINVALID_REPLACEMENT_CHARACTERCharacter used when an invalid characters is found.(package private) static intLONG_BITSNumber of bits in along.
-
Constructor Summary
Constructors Constructor Description CSSEncoder(CSSEncoder.Mode mode)Creates an encoder for the specified mode of operation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.nio.charset.CoderResultencodeArrays(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.protected intfirstEncodedOffset(java.lang.String input, int off, int len)Scans the input string for the first character index that requires encoding.protected intmaxEncodedLength(int n)Returns the maximum encoded length (in chars) of an input sequence ofncharacters.java.lang.StringtoString()-
Methods inherited from class org.owasp.encoder.Encoder
encode, encodeBuffers, overflow, underflow
-
-
-
-
Field Detail
-
LONG_BITS
static final int LONG_BITS
Number of bits in along.- See Also:
- Constant Field Values
-
HEX_ENCODED_LENGTH
static final int HEX_ENCODED_LENGTH
Length of hex encoding with trailing space"\## ".- See Also:
- Constant Field Values
-
INVALID_REPLACEMENT_CHARACTER
static final char INVALID_REPLACEMENT_CHARACTER
Character used when an invalid characters is found. Invalid characters may not appear with or without encoding.- See Also:
- Constant Field Values
-
_lowMask
final long _lowMask
The bit-mask of unescaped characters in the range 0 to 63.
-
_highMask
final long _highMask
The bit-mask of unescaped characters in the range 64 to 127.
-
_mode
final CSSEncoder.Mode _mode
The mode of operation, used primarily for toString.
-
-
Constructor Detail
-
CSSEncoder
CSSEncoder(CSSEncoder.Mode mode)
Creates an encoder for the specified mode of operation.- Parameters:
mode- the mode of the encoder.
-
-
Method Detail
-
maxEncodedLength
protected int maxEncodedLength(int n)
Description copied from class:EncoderReturns the maximum encoded length (in chars) of an input sequence ofncharacters.- Specified by:
maxEncodedLengthin classEncoder- Parameters:
n- the number of characters of input- Returns:
- the worst-case number of characters required to encode
-
firstEncodedOffset
protected int firstEncodedOffset(java.lang.String input, int off, int len)Description copied from class:EncoderScans 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:
firstEncodedOffsetin 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+lenif no characters in the input require encoding.
-
encodeArrays
protected java.nio.charset.CoderResult encodeArrays(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)Description copied from class:EncoderThe 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:
encodeArraysin classEncoder- Parameters:
input- the input buffer.output- the output buffer.endOfInput- when true, this is the last input to encode- Returns:
- UNDERFLOW or OVERFLOW
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-