Skip to content

Commit

Permalink
fix(command-dev): decode path component before matching redirects (#3107
Browse files Browse the repository at this point in the history
)
  • Loading branch information
erezrokah authored Aug 5, 2021
1 parent 1e5a8c3 commit 1125b03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/rules-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const createRewriter = async function ({ distDir, projectDir, jwtSecret, jwtRole
const matchReq = {
scheme: reqUrl.protocol.replace(/:.*$/, ''),
host: reqUrl.hostname,
path: reqUrl.pathname,
path: decodeURIComponent(reqUrl.pathname),
query: reqUrl.search.slice(1),
headers,
cookieValues,
Expand Down
18 changes: 18 additions & 0 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1809,5 +1809,23 @@ export const handler = async function () {
})
})
})

test(testName('should match redirect when path is URL encoded', args), async (t) => {
await withSiteBuilder('site-with-encoded-redirect', async (builder) => {
await builder
.withContentFile({ path: 'static/special[test].txt', content: `special` })
.withRedirectsFile({ redirects: [{ from: '/_next/static/*', to: '/static/:splat', status: 200 }] })
.buildAsync()

await withDevServer({ cwd: builder.directory, args }, async (server) => {
const [response1, response2] = await Promise.all([
got(`${server.url}/_next/static/special[test].txt`).text(),
got(`${server.url}/_next/static/special%5Btest%5D.txt`).text(),
])
t.is(response1, 'special')
t.is(response2, 'special')
})
})
})
})
/* eslint-enable require-await */

1 comment on commit 1125b03

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

Package size: 331 MB

Please sign in to comment.