Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix issue with query params

Steven Teya6de6f8046b0
diff --git a/lib/middleware/utils.ts b/lib/middleware/utils.ts
index 08a433ca14..2f25f61c5b 100644
--- a/lib/middleware/utils.ts
+++ b/lib/middleware/utils.ts
@@ -26,9 +26,11 @@ export const parse = (req: NextRequest) => {
};
export const getFinalUrl = (target: string, { req }: { req: NextRequest }) => {
- // query is the query string (e.g. dub.sh/github/repo?utm_source=twitter -> ?utm_source=twitter)
+ // query is the query string (e.g. dub.sh/github?utm_source=twitter -> ?utm_source=twitter)
const searchParams = req.nextUrl.searchParams;
+ if (searchParams.size === 0) return target; // if there are no query params, then return the target url as is (no need to parse it
+
// get the query params of the target url
const targetUrl = new URL(decodeURIComponent(target));