This utility class provides regex patterns for matching CSP grammar productions (schemes, hosts, ports, paths, media types, RFC 7230 tokens, IP addresses, etc.) as well as sentinel values for ports and a helper method for ASCII whitespace detection.
- Author:
- Salvation Team
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern matching a valid CSP directive name (ALPHA / DIGIT / "-").static final intSentinel value representing an empty (unspecified) port in a host-source.static final PatternPattern matching a CSP host-source expression.static final PatternPattern matching an IPv4 address in dotted-decimal notation.static final PatternPattern matching an IPv6 address, with or without enclosing brackets.static final PatternPattern matching the IPv6 loopback address (::1) in its various zero-expanded forms (e.g.static final PatternPattern matching a media type (type/subtype) per RFC 2045 §5.1.static final PatternPattern matching an RFC 7230 token (one or moretcharcharacters).static final StringRegex fragment matching a URI scheme per RFC 3986 §3.1.static final PatternPattern that matches a URI scheme followed by a colon at the start of a string.static final PatternPattern matching CSP keyword-like tokens that are missing their required single quotes (e.g.static final intSentinel value representing a wildcard port (:*) in a host-source. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisAsciiWhitespace(char c) Tests if a character is ASCII whitespace.
-
Field Details
-
SCHEME_PART
Regex fragment matching a URI scheme per RFC 3986 §3.1.Pattern:
[a-zA-Z][a-zA-Z0-9+\-.]*- See Also:
-
SCHEME_PATTERN
Pattern that matches a URI scheme followed by a colon at the start of a string.Named capture group:
scheme(includes the trailing colon). -
rfc7230TokenPattern
Pattern matching an RFC 7230 token (one or moretcharcharacters).- See Also:
-
MEDIA_TYPE_PATTERN
Pattern matching a media type (type/subtype) per RFC 2045 §5.1.Named capture groups:
typeandsubtype. -
UNQUOTED_KEYWORD_PATTERN
Pattern matching CSP keyword-like tokens that are missing their required single quotes (e.g.selfinstead of'self').Used to produce helpful warnings when an unquoted keyword is encountered in a source list.
-
WILDCARD_PORT
public static final int WILDCARD_PORTSentinel value representing a wildcard port (:*) in a host-source.Value:
-200- See Also:
-
EMPTY_PORT
public static final int EMPTY_PORTSentinel value representing an empty (unspecified) port in a host-source.Value:
-1- See Also:
-
HOST_SOURCE_PATTERN
Pattern matching a CSP host-source expression.Captures the optional scheme (
scheme), required host (host), optional port (port), and optional path (path) components.- See Also:
-
IPv4address
Pattern matching an IPv4 address in dotted-decimal notation.Each octet must be in the range 0–255.
-
IPV6loopback
Pattern matching the IPv6 loopback address (::1) in its various zero-expanded forms (e.g.0:0:0:0:0:0:0:1). -
IPv6addressWithOptionalBracket
Pattern matching an IPv6 address, with or without enclosing brackets.Matches both
[::1]and::1forms. -
DIRECTIVE_NAME_PATTERN
Pattern matching a valid CSP directive name (ALPHA / DIGIT / "-").
-
-
Method Details
-
isAsciiWhitespace
public static boolean isAsciiWhitespace(char c) Tests if a character is ASCII whitespace.ASCII whitespace characters are: tab (
\t), newline (\n), form feed (\f), carriage return (\r), and space.- Parameters:
c- the character to test- Returns:
trueif the character is ASCII whitespace,falseotherwise
-