Class SpaPathUtils

java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.SpaPathUtils

public final class SpaPathUtils extends Object
Utility methods for SPA path handling. This class provides common path operations used by IsolatedSpaRouteProvider and SpaNotFoundHandlerRegistry for consistent path matching behavior.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isPathUnderPrefix(String requestPath, String pathPrefix)
    Check if a request path is under a given path prefix.
    static String
    Normalize a path to ensure it starts with / and doesn't end with / (except for root path which stays as "/") Examples: normalizePath(null) -> "/" normalizePath("") -> "/" normalizePath("admin") -> "/admin" normalizePath("/admin") -> "/admin" normalizePath("/admin/") -> "/admin" normalizePath("/") -> "/"

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isPathUnderPrefix

      public static boolean isPathUnderPrefix(String requestPath, String pathPrefix)
      Check if a request path is under a given path prefix. This is the correct way to check path prefixes with boundary checking to prevent false matches like "/administrator" matching "/admin". Handles query parameters and hash fragments by stripping them before comparison, so "/admin?tab=users" correctly matches prefix "/admin". SPECIAL CASE - ROOT PATH: The root path "/" matches everything when used as a prefix. This allows root-level exclusions or catch-all behaviors. RULES: 1. Exact match: "/admin" matches "/admin" 2. Sub-path: "/admin/users" matches prefix "/admin" 3. Boundary check: "/administrator" does NOT match prefix "/admin" 4. Query params ignored: "/admin?tab=users" matches prefix "/admin" 5. Root matches all: anything matches prefix "/" This method ensures consistent path matching behavior across the routing system. Any code that needs to check "is path X under path Y" should use this logic to avoid prefix collision bugs. Examples: isPathUnderPrefix("/admin", "/admin") -> TRUE (exact) isPathUnderPrefix("/admin/users", "/admin") -> TRUE (sub-path) isPathUnderPrefix("/admin?tab=users", "/admin") -> TRUE (query param ignored) isPathUnderPrefix("/administrator", "/admin") -> FALSE (different path) isPathUnderPrefix("/api-docs", "/api") -> FALSE (different path) isPathUnderPrefix("/anything", "/") -> TRUE (root matches all)
      Parameters:
      requestPath - The request path to check (may include query params/hash)
      pathPrefix - The path prefix to match against
      Returns:
      true if requestPath is equal to or under pathPrefix
    • normalizePath

      public static String normalizePath(String path)
      Normalize a path to ensure it starts with / and doesn't end with / (except for root path which stays as "/") Examples: normalizePath(null) -> "/" normalizePath("") -> "/" normalizePath("admin") -> "/admin" normalizePath("/admin") -> "/admin" normalizePath("/admin/") -> "/admin" normalizePath("/") -> "/"
      Parameters:
      path - The path to normalize
      Returns:
      The normalized path