(currentUrl: URL, destination: string)
| 49 | * if it's external |
| 50 | */ |
| 51 | export function applyDestination(currentUrl: URL, destination: string): URL { |
| 52 | if (isExternalDestination(destination)) { |
| 53 | return new URL(destination) |
| 54 | } |
| 55 | |
| 56 | // Create a new URL with the updated pathname |
| 57 | const newUrl = new URL(currentUrl.toString()) |
| 58 | |
| 59 | // Handle destinations with query strings |
| 60 | const [pathname, search] = destination.split('?') |
| 61 | newUrl.pathname = pathname |
| 62 | |
| 63 | if (search) { |
| 64 | // Merge query parameters |
| 65 | const newParams = new URLSearchParams(search) |
| 66 | for (const [key, value] of newParams.entries()) { |
| 67 | newUrl.searchParams.set(key, value) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return newUrl |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Checks if a status code is a redirect status code |
no test coverage detected