Skip to content

Commit

Permalink
Make dynamic routes case-sensitive (vercel#15444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jul 25, 2020
1 parent f22f88f commit 574fe0b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/next-server/lib/router/utils/route-regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ export function getRouteRegex(
.join('')

return {
re: new RegExp(`^${parameterizedRoute}(?:/)?$`, 'i'),
re: new RegExp(`^${parameterizedRoute}(?:/)?$`),
groups,
routeKeys,
namedRegex: `^${namedParameterizedRoute}(?:/)?$`,
}
}

return {
re: new RegExp(`^${parameterizedRoute}(?:/)?$`, 'i'),
re: new RegExp(`^${parameterizedRoute}(?:/)?$`),
groups,
}
}
13 changes: 13 additions & 0 deletions test/integration/client-navigation/pages/dynamic/[slug]/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'

export default class DynamicRoute extends React.Component {
static async getInitialProps({ query = { slug: 'default' } }) {
return {
query,
}
}

render() {
return <p>{this.props.query.slug}</p>
}
}
22 changes: 22 additions & 0 deletions test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Client Navigation', () => {
'/url-prop-override',

'/dynamic/ssr',
'/dynamic/[slug]/route',

'/nav',
'/nav/about',
Expand Down Expand Up @@ -1002,6 +1003,27 @@ describe('Client Navigation', () => {
await browser.close()
})

it('should get url dynamic param', async () => {
const browser = await webdriver(
context.appPort,
'/dynamic/dynamic-part/route'
)
expect(await browser.elementByCss('p').text()).toBe('dynamic-part')
await browser.close()
})

it('should 404 on wrong casing of url dynamic param', async () => {
const browser = await webdriver(
context.appPort,
'/dynamic/dynamic-part/RoUtE'
)
expect(await browser.elementByCss('h1').text()).toBe('404')
expect(await browser.elementByCss('h2').text()).toBe(
'This page could not be found.'
)
await browser.close()
})

it('should not 404 for <page>/', async () => {
const browser = await webdriver(context.appPort, '/nav/about/')
const text = await browser.elementByCss('p').text()
Expand Down

0 comments on commit 574fe0b

Please sign in to comment.