Skip to content

Commit

Permalink
fix(vercel): handle dots in source path for redirects (#9289)
Browse files Browse the repository at this point in the history
* add fix

* add test

* add changeset
  • Loading branch information
lilnasy committed Dec 11, 2023
1 parent 8aa17a6 commit 8aeb0b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-socks-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fixes an issue where dots in redirects were incorrectly handled.
4 changes: 2 additions & 2 deletions packages/integrations/vercel/src/lib/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]) {
Expand Down
10 changes: 10 additions & 0 deletions packages/integrations/vercel/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Redirects', () => {
destination: '/',
},
'/blog/[...slug]': '/team/articles/[...slug]',
'/Basic/http-2-0.html': '/posts/http2',
},
trailingSlash: 'always',
});
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 8aeb0b5

Please sign in to comment.