@@ -20,6 +20,7 @@ import {
2020 relativeToAbsoluteUrl ,
2121 requiresUserInput ,
2222 sanitizeHref ,
23+ stripOrigin ,
2324 trimLeadingSlash ,
2425 trimTrailingSlash ,
2526} from '../url' ;
@@ -641,3 +642,32 @@ describe('relativeToAbsoluteUrl', () => {
641642 expect ( relativeToAbsoluteUrl ( relative , origin ) ) . toEqual ( new URL ( expected ) ) ;
642643 } ) ;
643644} ) ;
645+
646+ describe ( 'stripOrigin(url)' , ( ) => {
647+ it ( 'should strip origin when window.location is available' , ( ) => {
648+ const originalLocation = window . location ;
649+ Object . defineProperty ( window , 'location' , {
650+ value : { origin : 'https://example.com' } ,
651+ writable : true ,
652+ } ) ;
653+
654+ expect ( stripOrigin ( 'https://example.com/test?param=1' ) ) . toBe ( '/test?param=1' ) ;
655+ expect ( stripOrigin ( '/test' ) ) . toBe ( '/test' ) ;
656+
657+ Object . defineProperty ( window , 'location' , { value : originalLocation } ) ;
658+ } ) ;
659+
660+ it ( 'should handle undefined window.location gracefully' , ( ) => {
661+ const originalLocation = window . location ;
662+ Object . defineProperty ( window , 'location' , {
663+ value : undefined ,
664+ writable : true ,
665+ } ) ;
666+
667+ expect ( ( ) => stripOrigin ( '/test' ) ) . not . toThrow ( ) ;
668+ expect ( stripOrigin ( '/test' ) ) . toBe ( '/test' ) ;
669+ expect ( stripOrigin ( 'https://example.com/test' ) ) . toBe ( 'https://example.com/test' ) ;
670+
671+ Object . defineProperty ( window , 'location' , { value : originalLocation } ) ;
672+ } ) ;
673+ } ) ;
0 commit comments