File tree Expand file tree Collapse file tree 1 file changed +1
-26
lines changed
src/tools/safelink-decoder Expand file tree Collapse file tree 1 file changed +1
-26
lines changed Original file line number Diff line number Diff line change 11export 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 ( / \. s a f e l i n k s \. p r o t e c t i o n \. o u t l o o k \. c o m \/ \? u r l = .+ & d a t a = / ) ) {
11- // Extract the original URL
12- originalURL = originalURL . split ( '?url=' ) [ 1 ] . split ( '&data=' ) [ 0 ] ;
13- }
14- else if ( originalURL . match ( / \. s a f e l i n k s \. p r o t e c t i o n \. o u t l o o k \. c o m \/ \? u r l = .+ & a m p ; d a t a = / ) ) {
15- // Handle the case where "&" is encoded as "&"
16- originalURL = originalURL . split ( '?url=' ) [ 1 ] . split ( '&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}
You can’t perform that action at this time.
0 commit comments