MCPcopy
hub / github.com/coder/mux / parsePathnameFromRequestValue

Function parsePathnameFromRequestValue

src/node/orpc/server.ts:488–506  ·  view source on GitHub ↗
(value: string | null | undefined)

Source from the content-addressed store, hash-verified

486}
487
488function parsePathnameFromRequestValue(value: string | null | undefined): string | null {
489 if (!value) {
490 return null;
491 }
492
493 const trimmed = value.trim();
494 if (!trimmed || trimmed.startsWith("//")) {
495 return null;
496 }
497
498 try {
499 const pathname = trimmed.startsWith("/")
500 ? new URL(trimmed, "http://localhost").pathname
501 : new URL(trimmed).pathname;
502 return isValidUrlPathname(pathname) ? pathname : null;
503 } catch {
504 return null;
505 }
506}
507
508function getPathnameFromRequestUrl(requestUrl: string | undefined): string | null {
509 return parsePathnameFromRequestValue(requestUrl);

Callers 2

Calls 1

isValidUrlPathnameFunction · 0.85

Tested by

no test coverage detected