Skip to content

Commit c6583d4

Browse files
edykimpieh
authored andcommitted
feat(redirects): handle absolute from paths when path prefix is used (#12509)
## Description `toPath` in `createRedirect` handles path prefix properly, however, `fromPath` doesn't. I added the code for supporting the `fromPath` cases. Also, I added test cases of `createRedirect` action for the future. ## Related Issues Fixes #12497
1 parent 1c0af65 commit c6583d4

File tree

3 files changed

+463
-9
lines changed

3 files changed

+463
-9
lines changed
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Add redirects allows you to add redirects 1`] = `
4+
Object {
5+
"payload": Object {
6+
"fromPath": "/old/hello-world",
7+
"isPermanent": false,
8+
"redirectInBrowser": false,
9+
"toPath": "/new/hello-world",
10+
},
11+
"type": "CREATE_REDIRECT",
12+
}
13+
`;
14+
15+
exports[`Add redirects create redirects as permanent 1`] = `
16+
Object {
17+
"payload": Object {
18+
"fromPath": "/old/hello-world",
19+
"isPermanent": true,
20+
"redirectInBrowser": false,
21+
"toPath": "/new/hello-world",
22+
},
23+
"type": "CREATE_REDIRECT",
24+
}
25+
`;
26+
27+
exports[`Add redirects creates redirects from the URL starts with // 1`] = `
28+
Object {
29+
"payload": Object {
30+
"fromPath": "//example.com",
31+
"isPermanent": false,
32+
"redirectInBrowser": false,
33+
"toPath": "/new/hello-world-2",
34+
},
35+
"type": "CREATE_REDIRECT",
36+
}
37+
`;
38+
39+
exports[`Add redirects creates redirects from the URL starts with ftp 1`] = `
40+
Object {
41+
"payload": Object {
42+
"fromPath": "ftp://example.com",
43+
"isPermanent": false,
44+
"redirectInBrowser": false,
45+
"toPath": "/new/hello-world-3",
46+
},
47+
"type": "CREATE_REDIRECT",
48+
}
49+
`;
50+
51+
exports[`Add redirects creates redirects from the URL starts with http 1`] = `
52+
Object {
53+
"payload": Object {
54+
"fromPath": "http://example.com",
55+
"isPermanent": false,
56+
"redirectInBrowser": false,
57+
"toPath": "/new/hello-world-1",
58+
},
59+
"type": "CREATE_REDIRECT",
60+
}
61+
`;
62+
63+
exports[`Add redirects creates redirects from the URL starts with https 1`] = `
64+
Object {
65+
"payload": Object {
66+
"fromPath": "https://example.com",
67+
"isPermanent": false,
68+
"redirectInBrowser": false,
69+
"toPath": "/new/hello-world-0",
70+
},
71+
"type": "CREATE_REDIRECT",
72+
}
73+
`;
74+
75+
exports[`Add redirects creates redirects from the URL starts with mailto 1`] = `
76+
Object {
77+
"payload": Object {
78+
"fromPath": "mailto:[email protected]",
79+
"isPermanent": false,
80+
"redirectInBrowser": false,
81+
"toPath": "/new/hello-world-4",
82+
},
83+
"type": "CREATE_REDIRECT",
84+
}
85+
`;
86+
87+
exports[`Add redirects creates redirects to the URL starts with // 1`] = `
88+
Object {
89+
"payload": Object {
90+
"fromPath": "/old/hello-world-2",
91+
"isPermanent": false,
92+
"redirectInBrowser": false,
93+
"toPath": "//example.com",
94+
},
95+
"type": "CREATE_REDIRECT",
96+
}
97+
`;
98+
99+
exports[`Add redirects creates redirects to the URL starts with ftp 1`] = `
100+
Object {
101+
"payload": Object {
102+
"fromPath": "/old/hello-world-3",
103+
"isPermanent": false,
104+
"redirectInBrowser": false,
105+
"toPath": "ftp://example.com",
106+
},
107+
"type": "CREATE_REDIRECT",
108+
}
109+
`;
110+
111+
exports[`Add redirects creates redirects to the URL starts with http 1`] = `
112+
Object {
113+
"payload": Object {
114+
"fromPath": "/old/hello-world-1",
115+
"isPermanent": false,
116+
"redirectInBrowser": false,
117+
"toPath": "http://example.com",
118+
},
119+
"type": "CREATE_REDIRECT",
120+
}
121+
`;
122+
123+
exports[`Add redirects creates redirects to the URL starts with https 1`] = `
124+
Object {
125+
"payload": Object {
126+
"fromPath": "/old/hello-world-0",
127+
"isPermanent": false,
128+
"redirectInBrowser": false,
129+
"toPath": "https://example.com",
130+
},
131+
"type": "CREATE_REDIRECT",
132+
}
133+
`;
134+
135+
exports[`Add redirects creates redirects to the URL starts with mailto 1`] = `
136+
Object {
137+
"payload": Object {
138+
"fromPath": "/old/hello-world-4",
139+
"isPermanent": false,
140+
"redirectInBrowser": false,
141+
"toPath": "mailto:[email protected]",
142+
},
143+
"type": "CREATE_REDIRECT",
144+
}
145+
`;
146+
147+
exports[`Add redirects creates redirects with in-browser redirect option 1`] = `
148+
Object {
149+
"payload": Object {
150+
"fromPath": "/old/hello-world",
151+
"isPermanent": false,
152+
"redirectInBrowser": true,
153+
"toPath": "/new/hello-world",
154+
},
155+
"type": "CREATE_REDIRECT",
156+
}
157+
`;
158+
159+
exports[`Add redirects with path prefixs allows you to add redirects 1`] = `
160+
Object {
161+
"payload": Object {
162+
"fromPath": "/blog/old/hello-world",
163+
"isPermanent": false,
164+
"redirectInBrowser": false,
165+
"toPath": "/blog/new/hello-world",
166+
},
167+
"type": "CREATE_REDIRECT",
168+
}
169+
`;
170+
171+
exports[`Add redirects with path prefixs create redirects as permanent 1`] = `
172+
Object {
173+
"payload": Object {
174+
"fromPath": "/blog/old/hello-world",
175+
"isPermanent": true,
176+
"redirectInBrowser": false,
177+
"toPath": "/blog/new/hello-world",
178+
},
179+
"type": "CREATE_REDIRECT",
180+
}
181+
`;
182+
183+
exports[`Add redirects with path prefixs creates redirects from the URL starts with // 1`] = `
184+
Object {
185+
"payload": Object {
186+
"fromPath": "//example.com",
187+
"isPermanent": false,
188+
"redirectInBrowser": false,
189+
"toPath": "/blog/new/hello-world-2",
190+
},
191+
"type": "CREATE_REDIRECT",
192+
}
193+
`;
194+
195+
exports[`Add redirects with path prefixs creates redirects from the URL starts with ftp 1`] = `
196+
Object {
197+
"payload": Object {
198+
"fromPath": "ftp://example.com",
199+
"isPermanent": false,
200+
"redirectInBrowser": false,
201+
"toPath": "/blog/new/hello-world-3",
202+
},
203+
"type": "CREATE_REDIRECT",
204+
}
205+
`;
206+
207+
exports[`Add redirects with path prefixs creates redirects from the URL starts with http 1`] = `
208+
Object {
209+
"payload": Object {
210+
"fromPath": "http://example.com",
211+
"isPermanent": false,
212+
"redirectInBrowser": false,
213+
"toPath": "/blog/new/hello-world-1",
214+
},
215+
"type": "CREATE_REDIRECT",
216+
}
217+
`;
218+
219+
exports[`Add redirects with path prefixs creates redirects from the URL starts with https 1`] = `
220+
Object {
221+
"payload": Object {
222+
"fromPath": "https://example.com",
223+
"isPermanent": false,
224+
"redirectInBrowser": false,
225+
"toPath": "/blog/new/hello-world-0",
226+
},
227+
"type": "CREATE_REDIRECT",
228+
}
229+
`;
230+
231+
exports[`Add redirects with path prefixs creates redirects from the URL starts with mailto 1`] = `
232+
Object {
233+
"payload": Object {
234+
"fromPath": "mailto:[email protected]",
235+
"isPermanent": false,
236+
"redirectInBrowser": false,
237+
"toPath": "/blog/new/hello-world-4",
238+
},
239+
"type": "CREATE_REDIRECT",
240+
}
241+
`;
242+
243+
exports[`Add redirects with path prefixs creates redirects to the URL starts with // 1`] = `
244+
Object {
245+
"payload": Object {
246+
"fromPath": "/blog/old/hello-world-2",
247+
"isPermanent": false,
248+
"redirectInBrowser": false,
249+
"toPath": "//example.com",
250+
},
251+
"type": "CREATE_REDIRECT",
252+
}
253+
`;
254+
255+
exports[`Add redirects with path prefixs creates redirects to the URL starts with ftp 1`] = `
256+
Object {
257+
"payload": Object {
258+
"fromPath": "/blog/old/hello-world-3",
259+
"isPermanent": false,
260+
"redirectInBrowser": false,
261+
"toPath": "ftp://example.com",
262+
},
263+
"type": "CREATE_REDIRECT",
264+
}
265+
`;
266+
267+
exports[`Add redirects with path prefixs creates redirects to the URL starts with http 1`] = `
268+
Object {
269+
"payload": Object {
270+
"fromPath": "/blog/old/hello-world-1",
271+
"isPermanent": false,
272+
"redirectInBrowser": false,
273+
"toPath": "http://example.com",
274+
},
275+
"type": "CREATE_REDIRECT",
276+
}
277+
`;
278+
279+
exports[`Add redirects with path prefixs creates redirects to the URL starts with https 1`] = `
280+
Object {
281+
"payload": Object {
282+
"fromPath": "/blog/old/hello-world-0",
283+
"isPermanent": false,
284+
"redirectInBrowser": false,
285+
"toPath": "https://example.com",
286+
},
287+
"type": "CREATE_REDIRECT",
288+
}
289+
`;
290+
291+
exports[`Add redirects with path prefixs creates redirects to the URL starts with mailto 1`] = `
292+
Object {
293+
"payload": Object {
294+
"fromPath": "/blog/old/hello-world-4",
295+
"isPermanent": false,
296+
"redirectInBrowser": false,
297+
"toPath": "mailto:[email protected]",
298+
},
299+
"type": "CREATE_REDIRECT",
300+
}
301+
`;
302+
303+
exports[`Add redirects with path prefixs creates redirects with in-browser redirect option 1`] = `
304+
Object {
305+
"payload": Object {
306+
"fromPath": "/blog/old/hello-world",
307+
"isPermanent": false,
308+
"redirectInBrowser": true,
309+
"toPath": "/blog/new/hello-world",
310+
},
311+
"type": "CREATE_REDIRECT",
312+
}
313+
`;

0 commit comments

Comments
 (0)