9 lines · 252 B
/** `decodeURIComponent` that reports malformed percent-encoding as null so callers answer 400, not 500. */
export function safeDecode(segment: string): string | null {
  try {
    return decodeURIComponent(segment);
  } catch {
    return null;
  }
}