Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate i18n locale domain #50220

Merged
merged 3 commits into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/next/src/server/config.ts
Expand Up @@ -537,6 +537,13 @@ function assignDefaults(
if (!item.defaultLocale) return true
if (!item.domain || typeof item.domain !== 'string') return true

if (item.domain.includes(':')) {
console.warn(
`i18n domain: "${item.domain}" is invalid it should be a valid domain without https:// or port e.g. example.vercel.sh`
ijjk marked this conversation as resolved.
Show resolved Hide resolved
)
return true
}

const defaultLocaleDuplicate = i18n.domains?.find(
(altItem) =>
altItem.defaultLocale === item.defaultLocale &&
Expand Down
26 changes: 26 additions & 0 deletions test/integration/i18n-support/test/index.test.js
Expand Up @@ -550,4 +550,30 @@ describe('i18n Support', () => {
)
expect(stderr).toContain(`eN, fr`)
})

it('should show proper error for invalid locale domain', async () => {
nextConfig.write(`
module.exports = {
i18n: {
locales: ['en', 'fr', 'nl', 'eN', 'fr'],
domains: [
{
domain: 'hello:3000',
defaultLocale: 'en',
}
],
defaultLocale: 'en',
}
}
`)

const { code, stderr } = await nextBuild(appDir, undefined, {
stderr: true,
})
nextConfig.restore()
expect(code).toBe(1)
expect(stderr).toContain(
`i18n domain: "hello:3000" is invalid it should be a valid domain without https:// or port e.g. example.vercel.sh`
ijjk marked this conversation as resolved.
Show resolved Hide resolved
)
})
})