-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1741 from dubinc/fix-deeplink
fix deeplink encoding
- Loading branch information
Showing
1 changed file
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
export const runtime = "edge"; | ||
|
||
export default function DeepLinkPage({ params }: { params: { url: string } }) { | ||
// First decode the full URL parameter from the route | ||
const url = decodeURIComponent(params.url); | ||
// Split into base URL and query string | ||
const [baseUrl, queryString] = url.split("?"); | ||
|
||
return <meta httpEquiv="refresh" content={`0; url=${url}`} />; | ||
let redirectUrl = url; | ||
|
||
// if there are query parameters, we need to process them | ||
if (queryString) { | ||
// Parse the query string (but don't use toString() later as it adds extra encoding) | ||
const queryParams = new URLSearchParams(queryString); | ||
|
||
// Process each parameter with proper encoding | ||
const processedParams = Array.from(queryParams.entries()).map( | ||
([key, value]) => { | ||
// Handle form-encoded spaces ('+' → ' ') | ||
const decodedFromForm = value.replace(/\+/g, " "); | ||
// Decode any existing percent-encoding (e.g., '%26' → '&') | ||
const fullyDecoded = decodeURIComponent(decodedFromForm); | ||
// Apply one clean round of encoding | ||
const encoded = encodeURIComponent(fullyDecoded); | ||
|
||
return `${key}=${encoded}`; | ||
}, | ||
); | ||
|
||
// Reconstruct the URL with properly encoded parameters | ||
redirectUrl = `${baseUrl}?${processedParams.join("&")}`; | ||
} | ||
|
||
// Redirect to the redirect URL (which may be the same as the original URL, | ||
// or a cleaned-up version with properly encoded parameters) | ||
return <meta httpEquiv="refresh" content={`0; url=${redirectUrl}`} />; | ||
} |