Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vercel): handle dots in source path for redirects #9289

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('/');
}
Comment on lines -35 to 40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

image

After:

image


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
Loading