11import { resolvePath } from "react-router" ;
22
33describe ( "resolvePath" , ( ) => {
4+ it ( "does not touch with protocol-less absolute paths" , ( ) => {
5+ expect ( resolvePath ( "//google.com" ) ) . toMatchObject ( {
6+ pathname : "//google.com" ,
7+ } ) ;
8+
9+ expect ( resolvePath ( "//google.com/../../path" ) ) . toMatchObject ( {
10+ pathname : "//google.com/../../path" ,
11+ } ) ;
12+
13+ expect ( resolvePath ( "//google.com?q=query#hash" ) ) . toMatchObject ( {
14+ pathname : "//google.com" ,
15+ search : "?q=query" ,
16+ hash : "#hash" ,
17+ } ) ;
18+ } ) ;
19+
420 it ( 'resolves absolute paths irrespective of the "from" pathname' , ( ) => {
521 expect ( resolvePath ( "/search" , "/inbox" ) ) . toMatchObject ( {
622 pathname : "/search" ,
723 } ) ;
24+
25+ expect ( resolvePath ( "/search/../123" , "/inbox" ) ) . toMatchObject ( {
26+ pathname : "/123" ,
27+ } ) ;
28+
29+ expect ( resolvePath ( "/search/../../123" , "/inbox" ) ) . toMatchObject ( {
30+ pathname : "/123" ,
31+ } ) ;
32+
33+ expect ( resolvePath ( "/search/user/../../123" , "/inbox" ) ) . toMatchObject ( {
34+ pathname : "/123" ,
35+ } ) ;
836 } ) ;
937
1038 it ( "resolves relative paths" , ( ) => {
@@ -23,6 +51,32 @@ describe("resolvePath", () => {
2351 expect ( resolvePath ( "search" , "/inbox" ) ) . toMatchObject ( {
2452 pathname : "/inbox/search" ,
2553 } ) ;
54+
55+ expect ( resolvePath ( "search/../123" , "/inbox" ) ) . toMatchObject ( {
56+ pathname : "/inbox/123" ,
57+ } ) ;
58+
59+ expect ( resolvePath ( "search/../../123" , "/inbox" ) ) . toMatchObject ( {
60+ pathname : "/123" ,
61+ } ) ;
62+
63+ expect ( resolvePath ( "search/../../../123" , "/inbox" ) ) . toMatchObject ( {
64+ pathname : "/123" ,
65+ } ) ;
66+ } ) ;
67+
68+ it ( "normalizes any mid-path double-slashes" , ( ) => {
69+ let spy = jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
70+
71+ expect ( resolvePath ( "/search/../..//foo" ) ) . toMatchObject ( {
72+ pathname : "/foo" ,
73+ } ) ;
74+
75+ expect ( resolvePath ( "search/../..//foo" , "/inbox" ) ) . toMatchObject ( {
76+ pathname : "/foo" ,
77+ } ) ;
78+
79+ spy . mockRestore ( ) ;
2680 } ) ;
2781
2882 it ( 'ignores trailing slashes on the "from" pathname when resolving relative paths' , ( ) => {
0 commit comments