Use native URL parsing
Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
This commit is contained in:
parent
73deeb30e4
commit
ec6785e362
@ -1,28 +1,3 @@
|
|||||||
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
||||||
// Decode the ATP SafeLinks URL
|
return new URL(safeLinksUrl).searchParams.get('url')
|
||||||
let originalURL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Decode the URL
|
|
||||||
originalURL = decodeURIComponent(safeLinksUrl);
|
|
||||||
|
|
||||||
// Check if it matches the SafeLinks pattern
|
|
||||||
if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) {
|
|
||||||
// Extract the original URL
|
|
||||||
originalURL = originalURL.split('?url=')[1].split('&data=')[0];
|
|
||||||
}
|
|
||||||
else if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) {
|
|
||||||
// Handle the case where "&" is encoded as "&"
|
|
||||||
originalURL = originalURL.split('?url=')[1].split('&data=')[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('Invalid SafeLinks URL provided');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error: any) {
|
|
||||||
// Handle errors
|
|
||||||
throw new Error(`Failed to decode SafeLinks URL: ${error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return originalURL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user