Skip to content

Function: sanitizePathname()

API / @xmachines/play-router / sanitizePathname

function sanitizePathname(pathname): string | null;

Defined in: router-sync.ts:69

Normalize a pathname before route-map lookup.

This strips query/hash fragments, collapses duplicate slashes, and rejects implausibly long paths that should never enter route resolution.

Returns null for paths exceeding 2048 characters (malformed/adversarial input). Adapters that bypass RouterBridgeBase.syncActorFromRouter() (e.g. VueRouterBridge) must call this function directly and return early on null to apply the same defense-in-depth security guarantee as the shared base class.

Parameters

ParameterTypeDescription
pathnamestringRaw path string from router navigation event.

Returns

string | null

Normalized path string, or null if the path is malformed/too long.

Example

import { sanitizePathname } from "@xmachines/play-router";
const clean = sanitizePathname(to.path);
if (clean === null) return; // reject malformed path