@@ -188,6 +188,7 @@ export function hrefSanitizer(
188
188
const REMOVE_HASH_TRANSFORM_MARKER = 'removeHash' ;
189
189
const REMOVE_PARAM_TRANSFORM_MARKER = 'removeParam' ;
190
190
const MARKER_SEPARATOR = ':' ;
191
+ const COMMA = ',' ;
191
192
192
193
// Regular expression to find not valid characters at the beginning and at the end of the string,
193
194
// \x21-\x7e is a range that includes the ASCII characters from ! (hex 21) to ~ (hex 7E).
@@ -420,30 +421,28 @@ export function hrefSanitizer(
420
421
* @returns URL without the parameter(s) or empty string if no parameter is found
421
422
*/
422
423
const removeParam = ( url : string , transformValue : string ) => {
423
- // get the parameter values to remove
424
- const paramNamesToRemoveStr = transformValue . includes ( MARKER_SEPARATOR )
425
- ? transformValue . split ( MARKER_SEPARATOR ) [ 1 ]
426
- : undefined ;
427
-
428
424
const urlObj = new URL ( url , window . location . origin ) ;
429
425
430
- // if the parameter(s) value is specified, remove it
431
- if ( paramNamesToRemoveStr ) {
432
- const initSearchParamsLength = urlObj . searchParams . toString ( ) . length ;
426
+ // get the parameter values to remove
427
+ const paramNamesToRemoveStr = transformValue . split ( MARKER_SEPARATOR ) [ 1 ] ;
433
428
434
- const removeParams = paramNamesToRemoveStr . split ( ',' ) ;
435
- removeParams . forEach ( ( param ) => {
436
- if ( urlObj . searchParams . has ( param ) ) {
437
- urlObj . searchParams . delete ( param ) ;
438
- }
439
- } ) ;
429
+ if ( ! paramNamesToRemoveStr ) {
430
+ urlObj . search = '' ;
431
+ return urlObj . toString ( ) . replace ( window . location . origin , '' ) ;
432
+ }
440
433
441
- // if the parameter(s) is not found, return empty string
442
- if ( initSearchParamsLength === urlObj . searchParams . toString ( ) . length ) {
443
- return '' ;
434
+ const initSearchParamsLength = urlObj . searchParams . toString ( ) . length ;
435
+
436
+ const removeParams = paramNamesToRemoveStr . split ( COMMA ) ;
437
+ removeParams . forEach ( ( param ) => {
438
+ if ( urlObj . searchParams . has ( param ) ) {
439
+ urlObj . searchParams . delete ( param ) ;
444
440
}
445
- } else {
446
- urlObj . search = '' ;
441
+ } ) ;
442
+
443
+ // if the parameter(s) is not found, return empty string
444
+ if ( initSearchParamsLength === urlObj . searchParams . toString ( ) . length ) {
445
+ return '' ;
447
446
}
448
447
449
448
return urlObj . toString ( ) . replace ( window . location . origin , '' ) ;
0 commit comments