diff --git a/src/shared/plugins/plugin-content-pack-contributions.test.ts b/src/shared/plugins/plugin-content-pack-contributions.test.ts index b3d1708ee02..7b64f9a3f1c 100644 --- a/src/shared/plugins/plugin-content-pack-contributions.test.ts +++ b/src/shared/plugins/plugin-content-pack-contributions.test.ts @@ -120,6 +120,9 @@ describe('content-pack manifest contributions', () => { it.each([ ['language pack', { languagePacks: [{ locale: 'en_US', path: 'locale.json' }] }], + // Shape-legal but ill-formed: the regex alone let these load with dates falling back to English. + ['duplicate region', { languagePacks: [{ locale: 'en-US-US', path: 'locale.json' }] }], + ['unknown subtag', { languagePacks: [{ locale: 'en-aaa', path: 'locale.json' }] }], ['language pack path', { languagePacks: [{ locale: 'pt-BR', path: '../outside.json' }] }], ['VM recipe', { vmRecipes: [{ path: '\\\\server\\recipe.json' }] }], ['agent profile', { agents: [{ path: 'agents/../profile.json' }] }] @@ -127,6 +130,14 @@ describe('content-pack manifest contributions', () => { expect(parsePluginManifest(manifest(contributes)).ok).toBe(false) }) + it.each(['ru', 'pt-BR', 'zh-Hans-CN', 'en-US'])('accepts the well-formed locale %s', (locale) => { + expect( + parsePluginManifest(manifest({ languagePacks: [{ locale, path: 'locale.json' }] })) + ).toMatchObject({ + ok: true + }) + }) + it('rejects duplicate ids, locales, paths, and bindings', () => { const parsed = pluginManifestSchema.safeParse( manifest({ diff --git a/src/shared/plugins/plugin-content-pack-contributions.ts b/src/shared/plugins/plugin-content-pack-contributions.ts index 2ed599d11ba..e8e691ee12e 100644 --- a/src/shared/plugins/plugin-content-pack-contributions.ts +++ b/src/shared/plugins/plugin-content-pack-contributions.ts @@ -7,12 +7,24 @@ export const PLUGIN_KEYBINDING_LIMIT = 256 export const PLUGIN_VM_RECIPE_LIMIT = 64 export const PLUGIN_AGENT_PROFILE_LIMIT = 64 +/** True when Intl can parse the tag's grammar, not just its shape. */ +function isWellFormedLocaleId(value: string): boolean { + try { + Intl.getCanonicalLocales(value) + return true + } catch { + return false + } +} + // Locale IDs become filenames/i18next keys; a bounded BCP 47 subset excludes path syntax. +// Intl rejects shape-valid, ill-formed tags (`en-US-US`) at install, not silently when formatting. export const pluginLocaleIdSchema = z .string() .min(2) .max(35) .regex(/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/, 'must be a portable locale identifier') + .refine(isWellFormedLocaleId, 'must be a well-formed locale identifier') export const pluginLanguagePackContributionSchema = z .object({