mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
fix(vercel): handle dots in source path for redirects (#9289)
* add fix * add test * add changeset
This commit is contained in:
parent
8aa17a64b4
commit
8aeb0b5797
3 changed files with 17 additions and 2 deletions
5
.changeset/rotten-socks-help.md
Normal file
5
.changeset/rotten-socks-help.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Fixes an issue where dots in redirects were incorrectly handled.
|
|
@ -32,11 +32,11 @@ function getMatchPattern(segments: RoutePart[][]) {
|
|||
.replace(/#/g, '%23')
|
||||
.replace(/%5B/g, '[')
|
||||
.replace(/%5D/g, ']')
|
||||
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
.replace(/[*+?^${}()|[\]\\]/g, '\\$&');
|
||||
})
|
||||
.join('');
|
||||
})
|
||||
.join('');
|
||||
.join('/');
|
||||
}
|
||||
|
||||
function getReplacePattern(segments: RoutePart[][]) {
|
||||
|
|
|
@ -16,6 +16,7 @@ describe('Redirects', () => {
|
|||
destination: '/',
|
||||
},
|
||||
'/blog/[...slug]': '/team/articles/[...slug]',
|
||||
'/Basic/http-2-0.html': '/posts/http2',
|
||||
},
|
||||
trailingSlash: 'always',
|
||||
});
|
||||
|
@ -45,6 +46,15 @@ describe('Redirects', () => {
|
|||
expect(threeRoute.status).to.equal(302);
|
||||
});
|
||||
|
||||
it('define redirects for static files', async () => {
|
||||
const config = await getConfig();
|
||||
|
||||
const staticRoute = config.routes.find((r) => r.src === '/Basic/http-2-0.html');
|
||||
expect(staticRoute).to.not.be.undefined;
|
||||
expect(staticRoute.headers.Location).to.equal('/posts/http2');
|
||||
expect(staticRoute.status).to.equal(301);
|
||||
});
|
||||
|
||||
it('defines dynamic routes', async () => {
|
||||
const config = await getConfig();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue