Repository navigation
Description
Problem
On current main (9a925d2a38b893be735ff4429be8ad62132a204d), changing only the letter case of a locale's variant subtag can make negotiateLanguages select a different variant. I reproduced this on Node.js v24.19.0, macOS arm64, where "variants" in Intl.Locale.prototype is false.
Reproduction
Build the current checkout (npm ci, npm run build --workspaces), then run from its root:
import { negotiateLanguages } from "./fluent-langneg/esm/index.js";
console.log(negotiateLanguages(
["en-oxendict"],
["en-US-fonipa", "en-US-oxendict"],
{ strategy: "matching" }
));
// ["en-US-oxendict"]
console.log(negotiateLanguages(
["en-oxendict"],
["en-US-fonipa", "en-US-OXENDICT"],
{ strategy: "matching" }
));
// Actual: ["en-US-fonipa"]
// Expected: ["en-US-OXENDICT"]The same difference occurs with strategy: "lookup", defaultLocale: "fr". Uppercasing the requested variant (en-OXENDICT) while leaving both available tags lowercase also selects en-US-fonipa instead of en-US-oxendict.
oxendict and fonipa are registered variants for Oxford English Dictionary spelling and the International Phonetic Alphabet, respectively. An application using the selected tag to choose resources can therefore select the other variant solely because of capitalization. This report demonstrates the library result locally; it does not assert that a deployed application is affected.
Expected behavior and cause
RFC 4647 section 2 requires case-insensitive language tag/range matching. Capitalization should not change the selected variant; the original spelling of the selected available tag should still be returned.
In LocaleWrapper, the fallback .variants value is extracted from the original tag, retaining its case. The native Intl.Locale fields are normalized, but the fallback variant is not. The range/likely-subtag comparison then uses strict equality for .variants in matches.ts. Exact full-tag matching already lowercases the strings, so this reproduction intentionally requests en-oxendict against en-US-... resources.
This reproduction is limited to the fallback path without a native .variants getter. I have not verified it in Firefox or other browsers, and I am not claiming it was introduced by the recent Intl.Locale migration.
Suggested fix and verification
The attached patch lowercases the internal tag before constructing Intl.Locale and extracting fallback variants. It keeps the original available-locale strings in the returned result. It adds six public-API regression cases covering a lowercase control, uppercase available variant, and uppercase requested variant, under both matching and lookup.
- With the original source, the four uppercase cases fail and the two lowercase controls pass.
- With the patch, all six cases pass. A separate run against built JavaScript confirms the same before/after outputs.
- Full suite: 740 passed, 3 existing skipped, across 58 test files.
- Workspace build, lint, and API documentation generation pass; the patch applies cleanly to the cited commit.
I searched open/closed issues and PRs for variant case, case-insensitive matching, oxendict, fonipa, and LocaleWrapper, and reviewed the related #605/#602 discussion. I did not find a report of this specific case mismatch.
AI tools assisted with source review, drafting, and the patch. The reproduction, failing regression tests, built-output comparison, and validation commands were actually executed locally before submission.
Activity