From ec6785e36263dade4ceea03702da36b899f45a7d Mon Sep 17 00:00:00 2001 From: sharevb Date: Sun, 3 Mar 2024 11:44:12 +0100 Subject: [PATCH] Use native URL parsing Co-authored-by: Corentin THOMASSET --- .../safelink-decoder.service.ts | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/tools/safelink-decoder/safelink-decoder.service.ts b/src/tools/safelink-decoder/safelink-decoder.service.ts index 8653b963..2b94bcd8 100644 --- a/src/tools/safelink-decoder/safelink-decoder.service.ts +++ b/src/tools/safelink-decoder/safelink-decoder.service.ts @@ -1,28 +1,3 @@ export function decodeSafeLinksURL(safeLinksUrl: string) { - // Decode the ATP SafeLinks 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; + return new URL(safeLinksUrl).searchParams.get('url') }