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 long URLs causing 400s with dynamic routes/rewrites #26221

Merged
merged 3 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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