From ae1d271f9ab77c63036d4901155a089d13392ea2 Mon Sep 17 00:00:00 2001 From: vordgi <91429106+vordgi@users.noreply.github.com> Date: Thu, 11 Nov 2021 04:29:20 +0200 Subject: [PATCH] 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 --- packages/next/server/router.ts | 4 +-- .../i18n-support/test/index.test.js | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/next/server/router.ts b/packages/next/server/router.ts index fb0176c03274139..a9a9f6e4fb710d7 100644 --- a/packages/next/server/router.ts +++ b/packages/next/server/router.ts @@ -318,9 +318,9 @@ export default class Router { currentPathname = `${ getRequestMeta(req, '_nextHadBasePath') ? activeBasePath : '' }${ - activeBasePath && localePathResult.pathname === '/' + activeBasePath && currentPathnameNoBasePath === '/' ? '' - : localePathResult.pathname + : currentPathnameNoBasePath }` } diff --git a/test/integration/i18n-support/test/index.test.js b/test/integration/i18n-support/test/index.test.js index 7d8143b79a0900f..8212a6bb0827e46 100644 --- a/test/integration/i18n-support/test/index.test.js +++ b/test/integration/i18n-support/test/index.test.js @@ -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}/` : ''}`