Unverified Commit ae1d271f authored by vordgi's avatar vordgi Committed by GitHub

bugfix/i18n Do not support the second locale in the pathname (#31229)



## Bug

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

Fixes: https://github.com/vercel/next.js/issues/31228
parent c791da09
......@@ -318,9 +318,9 @@ export default class Router {
currentPathname = `${
getRequestMeta(req, '_nextHadBasePath') ? activeBasePath : ''
}${
activeBasePath && localePathResult.pathname === '/'
activeBasePath && currentPathnameNoBasePath === '/'
? ''
: localePathResult.pathname
: currentPathnameNoBasePath
}`
}
......
......@@ -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}/` : ''}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment