Class Constants

java.lang.Object
org.htmlunit.csp.Constants

public final class Constants extends Object
Shared constants used throughout the CSP parser.

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 Details

    • SCHEME_PART

      public static final String 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

      public static final Pattern 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

      public static final Pattern rfc7230TokenPattern
      Pattern matching an RFC 7230 token (one or more tchar characters).
      See Also:
    • MEDIA_TYPE_PATTERN

      public static final Pattern MEDIA_TYPE_PATTERN
      Pattern matching a media type (type/subtype) per RFC 2045 §5.1.

      Named capture groups: type and subtype.

    • UNQUOTED_KEYWORD_PATTERN

      public static final Pattern UNQUOTED_KEYWORD_PATTERN
      Pattern matching CSP keyword-like tokens that are missing their required single quotes (e.g. self instead of 'self').

      Used to produce helpful warnings when an unquoted keyword is encountered in a source list.

    • WILDCARD_PORT

      public static final int WILDCARD_PORT
      Sentinel value representing a wildcard port (:*) in a host-source.

      Value: -200

      See Also:
    • EMPTY_PORT

      public static final int EMPTY_PORT
      Sentinel value representing an empty (unspecified) port in a host-source.

      Value: -1

      See Also:
    • HOST_SOURCE_PATTERN

      public static final Pattern 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

      public static final Pattern IPv4address
      Pattern matching an IPv4 address in dotted-decimal notation.

      Each octet must be in the range 0–255.

    • IPV6loopback

      public static final Pattern 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

      public static final Pattern IPv6addressWithOptionalBracket
      Pattern matching an IPv6 address, with or without enclosing brackets.

      Matches both [::1] and ::1 forms.

    • DIRECTIVE_NAME_PATTERN

      public static final Pattern 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:
      true if the character is ASCII whitespace, false otherwise