Function: sanitizePathname()
API / @xmachines/play-router / sanitizePathname
function sanitizePathname(pathname): string | null;Defined in: router-sync.ts:74
Normalizes a pathname before a lookup in the route map.
The function removes a query fragment and a hash fragment, it joins each duplicate slash into one, and it refuses a path of an improbable length, because such a path must never enter the route resolution.
It returns null for a path of more than 2048 characters, which is malformed or
hostile input. An adapter that passes around
RouterBridgeBase.syncActorFromRouter(), for example VueRouterBridge, must call
this function itself, and it must return at once on a null value. That adapter
then gives the same guarantee of the defense in depth as the shared base class.
Parameters
| Parameter | Type | Description |
|---|---|---|
pathname | string | The raw path string of a navigation event of the router. |
Returns
string | null
The normalized path string, or null when the path is malformed or too long.
Example
import { sanitizePathname } from "@xmachines/play-router";
const clean = sanitizePathname(to.path);if (clean === null) return; // refuse a malformed path