(value: string | null | undefined)
| 486 | } |
| 487 | |
| 488 | function 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 | |
| 508 | function getPathnameFromRequestUrl(requestUrl: string | undefined): string | null { |
| 509 | return parsePathnameFromRequestValue(requestUrl); |
no test coverage detected