Skip to content

Commit

Permalink
bug (#21943): remove incorrect rewrite of parsedUrl.pathname in serve…
Browse files Browse the repository at this point in the history
…rless handler (#22445)

Fixes #21943

i confirmed in a personal test repo that this solves the issue of infinite 307s on root level non-default locales :)  let me know what else this needs if anything! thanks for the time/help @ijjk ❤️
  • Loading branch information
lindsaylevine authored Feb 25, 2021
1 parent 69fe678 commit b1a1c80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export function getUtils({
shouldNotRedirect: boolean
) {
if (!i18n) return
const pathname = parsedUrl.pathname || '/'

let defaultLocale = i18n.defaultLocale
let detectedLocale = detectLocaleCookie(req, i18n.locales)
Expand All @@ -356,10 +357,7 @@ export function getUtils({
detectedLocale = detectedLocale || acceptPreferredLocale

let localeDomainRedirect
const localePathResult = normalizeLocalePath(
parsedUrl.pathname!,
i18n.locales
)
const localePathResult = normalizeLocalePath(pathname, i18n.locales)

routeNoAssetPath = normalizeLocalePath(routeNoAssetPath, i18n.locales)
.pathname
Expand Down Expand Up @@ -395,7 +393,7 @@ export function getUtils({
}
}

const denormalizedPagePath = denormalizePagePath(parsedUrl.pathname || '/')
const denormalizedPagePath = denormalizePagePath(pathname)
const detectedDefaultLocale =
!detectedLocale ||
detectedLocale.toLowerCase() === defaultLocale.toLowerCase()
Expand Down
5 changes: 5 additions & 0 deletions test/integration/i18n-support-catchall/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,16 @@ describe('i18n Support Root Catch-all', () => {
redirect: 'manual',
})

const res4 = await fetchViaHTTP(port, '/fr', undefined, {
redirect: 'manual',
})

server.close()

expect(res.status).toBe(200)
expect(res2.status).toBe(200)
expect(res3.status).toBe(200)
expect(res4.status).toBe(200)

const $ = cheerio.load(await res.text())
const $2 = cheerio.load(await res2.text())
Expand Down

0 comments on commit b1a1c80

Please sign in to comment.