Skip to content

Don't append Unicode extensions to a default locale that already has one - #5126

Open
jessealama wants to merge 2 commits into
tc39:mainfrom
jessealama:locale-base-name-helper
Open

Don't append Unicode extensions to a default locale that already has one#5126
jessealama wants to merge 2 commits into
tc39:mainfrom
jessealama:locale-base-name-helper

Conversation

@jessealama

Copy link
Copy Markdown
Contributor

Fixes #615.

testNumberFormat and nine standalone tests build locales by appending strings like "-u-<key>-<value>" to the default locale coming from resolvedOptions(). When a host reports a default locale that already carries a Unicode extension sequence (e.g. "en-US-u-va-posix"), the result has two "-u-" substrings. This causes the constructor to throw a RangeError before these tests reach the behavior they're meant to check. JSC does this in CI, where 43 tests currently fail for that reason.

This PR adds a new getLocaleBaseName helper to testIntl.js. It strips extension and private-use subtags (thereby mirroring Intl.Locale.p.baseName). The helper is then applied at each site before any extension gets appended.

Whether the default locale may contain an extension at all is a separate question, covered by a new conformance test in #5125.

The helper uses plain string juggling rather than Intl.Locale. That's arguably a more proper solution, but using Intl.Locale would add a feature dependency to legacy Collator and NumberFormat tests. I also notice that V8's baseName currently returns "en-US-u-va-posix" unchanged for exactly this input, so the helper wouldn't do anything there. Switching to Intl.Locale once both concerns are resolved would be a reasonable follow-up.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

9 new or modified tests were run on 7 engines.

View workflow run

Test Engine262 GraalJS JavaScriptCore QuickJS SpiderMonkey V8 XS
intl402/Collator/ignore-invalid-unicode-ext-values.js
intl402/Collator/numeric-and-caseFirst.js
intl402/DateTimeFormat/casing-numbering-system-calendar-options.js
intl402/DateTimeFormat/numbering-system-calendar-options.js
intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js
intl402/NumberFormat/casing-numbering-system-options.js
intl402/NumberFormat/numbering-system-options.js
intl402/NumberFormat/test-option-currency.js
intl402/NumberFormat/throws-for-currency-style-without-currency-option.js

@ptomato ptomato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not positive about what the right move is here. This seems to work fine. But on the other hand, it seems simpler (and arguably more robust) to insert the extension sequences in the right place with an addUExtension(key, value) helper function:

  • If there's no -u-, append -u-${key}-${value}.
  • If there is -u- and no other single-letter subtags after it, append -${key}-${value}.
  • If there is -u- and any other single-letter subtag after it, insert -${key}-${value}- right before the first such single-letter subtag.

…cale

The Collator test for ignored invalid extension values now builds its
baseline collator from the base name as well, so that its resolved-locale
and resolved-options comparisons use the same locale as the collators
under test.
@jessealama
jessealama force-pushed the locale-base-name-helper branch from ac404b9 to bd837ab Compare September 6, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collator and NumberFormats test append '-u-key-value' without checking if the default locale already has '-u-'.

2 participants