Skip to content

Commit

Permalink
fix: reverse back quotes to sanitize
Browse files Browse the repository at this point in the history
Co-authored-by: Iris Booker <iris.booker@getbraintree.com>
  • Loading branch information
braintreeps and Iris Booker committed Jul 15, 2024
1 parent 3994005 commit 3bbf710
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,25 @@ export function sanitizeUrl(url?: string): string {
return BLANK_URL;
}

const backSanitized = trimmedUrl.replace(/\\/g, "/");

// Handle special cases for mailto: and custom deep-link protocols
if (urlScheme === "mailto:" || urlScheme.includes("://")) {
return trimmedUrl;
return backSanitized;
}

// For http and https URLs, perform additional validation
if (urlScheme === "http:" || urlScheme === "https:") {
if (!isValidUrl(trimmedUrl)) {
if (!isValidUrl(backSanitized)) {
return BLANK_URL;
}

const url = new URL(trimmedUrl);
const url = new URL(backSanitized);
url.protocol = url.protocol.toLowerCase();
url.hostname = url.hostname.toLowerCase();

return url.toString();
}

return trimmedUrl;
return backSanitized;
}

0 comments on commit 3bbf710

Please sign in to comment.