* Format a `server.listen()` host value for use inside a URL. * * - IPv6 literals must be wrapped in brackets (e.g. "::1" -> "[::1]") * - Zone identifiers must be percent-encoded ("%" -> "%25")
(rawHost: string)
| 93 | * - Zone identifiers must be percent-encoded ("%" -> "%25") |
| 94 | */ |
| 95 | function hostForRedirectUri(rawHost: string): string { |
| 96 | const host = rawHost.startsWith("[") && rawHost.endsWith("]") ? rawHost.slice(1, -1) : rawHost; |
| 97 | |
| 98 | if (host.includes(":")) { |
| 99 | // RFC 6874: zone identifiers use "%25" in URIs. |
| 100 | return `[${host.replaceAll("%", "%25")}]`; |
| 101 | } |
| 102 | |
| 103 | return host; |
| 104 | } |
| 105 | |
| 106 | // --------------------------------------------------------------------------- |
| 107 | // Main |
no outgoing calls
no test coverage detected