Skip to content

Commit

Permalink
bugfix/i18n Do not support the second locale in the pathname (#31229)
Browse files Browse the repository at this point in the history
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

Fixes: #31228
  • Loading branch information
vordgi committed Nov 11, 2021
1 parent c791da0 commit ae1d271
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/server/router.ts
Expand Up @@ -318,9 +318,9 @@ export default class Router {
currentPathname = `${
getRequestMeta(req, '_nextHadBasePath') ? activeBasePath : ''
}${
activeBasePath && localePathResult.pathname === '/'
activeBasePath && currentPathnameNoBasePath === '/'
? ''
: localePathResult.pathname
: currentPathnameNoBasePath
}`
}

Expand Down
31 changes: 31 additions & 0 deletions test/integration/i18n-support/test/index.test.js
Expand Up @@ -412,6 +412,37 @@ describe('i18n Support', () => {
}
})

it('should return 404 error for repeating locales', async () => {
const defaultLocale = 'en-US'
for (const locale of nonDomainLocales) {
for (const asPath of [
'/gsp/fallback/always/',
'/post/comment/',
'/gssp/first/',
]) {
const res = await fetchViaHTTP(
curCtx.appPort,
`/${locale}/${defaultLocale}${asPath}`,
undefined,
{
redirect: 'manual',
}
)
expect(res.status).toBe(404)
const $ = cheerio.load(await res.text())
const props = JSON.parse($('#props').text())
console.log(props)
expect($('#not-found').text().length > 0).toBe(true)
expect(props).toEqual({
is404: true,
locale,
locales,
defaultLocale,
})
}
}
})

it('should navigate between pages correctly', async () => {
for (const locale of nonDomainLocales) {
const localePath = `/${locale !== 'en-US' ? `${locale}/` : ''}`
Expand Down

0 comments on commit ae1d271

Please sign in to comment.