Skip to content

Commit

Permalink
fix(pong): avoid duplicate "https:" (#11212)
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner authored May 30, 2024
1 parent 00bf253 commit c4ef726
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libs/pong/pong2.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function createPong2ClickHandler(coder) {
}

const anonymousIp = anonymousIpByCC(countryCode);
const clickURL = new URL(`https:${click}`);
const clickURL = createURL(click);
clickURL.searchParams.set("forwardedip", anonymousIp);
clickURL.searchParams.set("useragent", userAgent);

Expand All @@ -140,7 +140,7 @@ export function createPong2ViewedHandler(coder) {
const view = coder.decodeAndVerify(params.get("code"));
if (view) {
const anonymousIp = anonymousIpByCC(countryCode);
const viewURL = new URL(`https:${view}`);
const viewURL = createURL(view);
viewURL.searchParams.set("forwardedip", anonymousIp);
viewURL.searchParams.set("useragent", userAgent);

Expand All @@ -150,3 +150,16 @@ export function createPong2ViewedHandler(coder) {
}
};
}

function createURL(payload) {
if (payload.startsWith("//")) {
// BSA omitted 'https:' until May 2024.
return new URL(`https:${payload}`);
}

if (!payload.startsWith("https://")) {
console.error(`Invalid URL payload: ${payload}`);
}

return new URL(payload);
}

0 comments on commit c4ef726

Please sign in to comment.