Class Utils

java.lang.Object
org.htmlunit.csp.Utils

public final class Utils extends Object
Internal utility methods and constants used by the CSP parser.

Provides string-manipulation helpers that follow the algorithms defined in the Infra Standard, including split on ASCII whitespace and strictly split, as well as Base64 validation, URL-decoding, and token extraction.

Author:
Salvation Team
  • Field Details

    • IS_BASE64_VALUE

      public static final Predicate<String> IS_BASE64_VALUE
      Predicate that tests whether a string matches the Base64 value grammar used in CSP nonce-sources and hash-sources.

      Accepts characters a-zA-Z0-9+/-_ followed by zero, one, or two padding = characters.

  • Method Details

    • trimAsciiWhitespace

      public static String trimAsciiWhitespace(String str)
      Trims leading and trailing ASCII whitespace (\t, \n, \f, \r, and space) from the given string.
      Parameters:
      str - the string to trim (can be null)
      Returns:
      the trimmed string, or null if the input is null, or an empty string if the input consists entirely of whitespace
    • extractLeadingToken

      public static String extractLeadingToken(String input)
      Extracts the first contiguous sequence of non-ASCII-whitespace characters from the beginning of the input string.

      If the string starts with whitespace, is null, or is empty, an empty string is returned.

      Parameters:
      input - the input string (can be null)
      Returns:
      the leading token, or an empty string if no leading token is present