Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Fix long URLs causing 400s with dynamic routes/rewrites (vercel#26221)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ijjk and kodiakhq[bot] authored Jun 17, 2021
1 parent c75c2db commit 19b12f1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/lib/file-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function fileExists(
}
return true
} catch (err) {
if (err.code === 'ENOENT') {
if (err.code === 'ENOENT' || err.code === 'ENAMETOOLONG') {
return false
}
throw err
Expand Down
11 changes: 11 additions & 0 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ let appPort
let app

const runTests = (isDev = false) => {
it('should support long URLs for rewrites', async () => {
const res = await fetchViaHTTP(
appPort,
'/catchall-rewrite/a9btBxtHQALZ6cxfuj18X6OLGNSkJVzrOXz41HG4QwciZfn7ggRZzPx21dWqGiTBAqFRiWvVNm5ko2lpyso5jtVaXg88dC1jKfqI2qmIcdeyJat8xamrIh2LWnrYRrsBcoKfQU65KHod8DPANuzPS3fkVYWlmov05GQbc82HwR1exOvPVKUKb5gBRWiN0WOh7hN4QyezIuq3dJINAptFQ6m2bNGjYACBRk4MOSHdcQG58oq5Ch7luuqrl9EcbWSa'
)

const html = await res.text()
expect(res.status).toBe(200)
expect(html).toContain('/with-params')
})

it('should resolveHref correctly navigating through history', async () => {
const browser = await webdriver(appPort, '/')
await browser.eval('window.beforeNav = 1')
Expand Down
4 changes: 3 additions & 1 deletion test/integration/dynamic-routing/pages/dash/[hello-world].js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default () => 'hi'
export default function Page(props) {
return 'hi'
}
12 changes: 12 additions & 0 deletions test/integration/dynamic-routing/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ const appDir = join(__dirname, '../')
const buildIdPath = join(appDir, '.next/BUILD_ID')

function runTests(dev) {
it('should support long URLs for dynamic routes', async () => {
const res = await fetchViaHTTP(
appPort,
'/dash/a9btBxtHQALZ6cxfuj18X6OLGNSkJVzrOXz41HG4QwciZfn7ggRZzPx21dWqGiTBAqFRiWvVNm5ko2lpyso5jtVaXg88dC1jKfqI2qmIcdeyJat8xamrIh2LWnrYRrsBcoKfQU65KHod8DPANuzPS3fkVYWlmov05GQbc82HwR1exOvPVKUKb5gBRWiN0WOh7hN4QyezIuq3dJINAptFQ6m2bNGjYACBRk4MOSHdcQG58oq5Ch7luuqrl9EcbWSa'
)

const html = await res.text()
expect(res.status).toBe(200)
expect(html).toContain('hi')
expect(html).toContain('/dash/[hello-world]')
})

it('should handle only query on dynamic route', async () => {
const browser = await webdriver(appPort, '/post-1')

Expand Down
2 changes: 1 addition & 1 deletion test/integration/production/pages/invalid-param/[slug].js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from 'next/router'

export default function Page() {
return <p>hello {useRouter().query}</p>
return <p>hello {useRouter().query.slug}</p>
}

export const getServerSideProps = () => {
Expand Down

0 comments on commit 19b12f1

Please sign in to comment.