Skip to content

Commit

Permalink
feat(redirects): handle absolute from paths when path prefix is used (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
edykim authored and pieh committed Mar 13, 2019
1 parent 1c0af65 commit c6583d4
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 9 deletions.
313 changes: 313 additions & 0 deletions packages/gatsby/src/redux/__tests__/__snapshots__/redirects.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Add redirects allows you to add redirects 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects create redirects as permanent 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world",
"isPermanent": true,
"redirectInBrowser": false,
"toPath": "/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects from the URL starts with // 1`] = `
Object {
"payload": Object {
"fromPath": "//example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world-2",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects from the URL starts with ftp 1`] = `
Object {
"payload": Object {
"fromPath": "ftp://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world-3",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects from the URL starts with http 1`] = `
Object {
"payload": Object {
"fromPath": "http://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world-1",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects from the URL starts with https 1`] = `
Object {
"payload": Object {
"fromPath": "https://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world-0",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects from the URL starts with mailto 1`] = `
Object {
"payload": Object {
"fromPath": "mailto:example@email.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/new/hello-world-4",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects to the URL starts with // 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world-2",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "//example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects to the URL starts with ftp 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world-3",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "ftp://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects to the URL starts with http 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world-1",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "http://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects to the URL starts with https 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world-0",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "https://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects to the URL starts with mailto 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world-4",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "mailto:example@email.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects creates redirects with in-browser redirect option 1`] = `
Object {
"payload": Object {
"fromPath": "/old/hello-world",
"isPermanent": false,
"redirectInBrowser": true,
"toPath": "/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs allows you to add redirects 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs create redirects as permanent 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world",
"isPermanent": true,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects from the URL starts with // 1`] = `
Object {
"payload": Object {
"fromPath": "//example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world-2",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects from the URL starts with ftp 1`] = `
Object {
"payload": Object {
"fromPath": "ftp://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world-3",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects from the URL starts with http 1`] = `
Object {
"payload": Object {
"fromPath": "http://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world-1",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects from the URL starts with https 1`] = `
Object {
"payload": Object {
"fromPath": "https://example.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world-0",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects from the URL starts with mailto 1`] = `
Object {
"payload": Object {
"fromPath": "mailto:example@email.com",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "/blog/new/hello-world-4",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects to the URL starts with // 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world-2",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "//example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects to the URL starts with ftp 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world-3",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "ftp://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects to the URL starts with http 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world-1",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "http://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects to the URL starts with https 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world-0",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "https://example.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects to the URL starts with mailto 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world-4",
"isPermanent": false,
"redirectInBrowser": false,
"toPath": "mailto:example@email.com",
},
"type": "CREATE_REDIRECT",
}
`;

exports[`Add redirects with path prefixs creates redirects with in-browser redirect option 1`] = `
Object {
"payload": Object {
"fromPath": "/blog/old/hello-world",
"isPermanent": false,
"redirectInBrowser": true,
"toPath": "/blog/new/hello-world",
},
"type": "CREATE_REDIRECT",
}
`;
Loading

0 comments on commit c6583d4

Please sign in to comment.