Skip to content

Commit ec6785e

Browse files
sharevbCorentinTh
andauthored
Use native URL parsing
Co-authored-by: Corentin THOMASSET <[email protected]>
1 parent 73deeb3 commit ec6785e

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
11
export function decodeSafeLinksURL(safeLinksUrl: string) {
2-
// Decode the ATP SafeLinks URL
3-
let originalURL;
4-
5-
try {
6-
// Decode the URL
7-
originalURL = decodeURIComponent(safeLinksUrl);
8-
9-
// Check if it matches the SafeLinks pattern
10-
if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) {
11-
// Extract the original URL
12-
originalURL = originalURL.split('?url=')[1].split('&data=')[0];
13-
}
14-
else if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&amp;data=/)) {
15-
// Handle the case where "&" is encoded as "&amp;"
16-
originalURL = originalURL.split('?url=')[1].split('&amp;data=')[0];
17-
}
18-
else {
19-
throw new Error('Invalid SafeLinks URL provided');
20-
}
21-
}
22-
catch (error: any) {
23-
// Handle errors
24-
throw new Error(`Failed to decode SafeLinks URL: ${error}`);
25-
}
26-
27-
return originalURL;
2+
return new URL(safeLinksUrl).searchParams.get('url')
283
}

0 commit comments

Comments
 (0)