0
Fork 0
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:
Arsh 2023-12-11 22:20:22 +00:00 committed by GitHub
parent 8aa17a64b4
commit 8aeb0b5797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Fixes an issue where dots in redirects were incorrectly handled.

View file

@ -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[][]) {

View file

@ -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();