close
Skip to content

Editorial: Fix incorrect validation of variants for Intl.Locale construction#1007

Merged
gibson042 merged 1 commit into
tc39:mainfrom
gibson042:gh-1006-locale-variants-validation
May 30, 2025
Merged

Editorial: Fix incorrect validation of variants for Intl.Locale construction#1007
gibson042 merged 1 commit into
tc39:mainfrom
gibson042:gh-1006-locale-variants-validation

Conversation

@gibson042
Copy link
Copy Markdown
Member

@gibson042 gibson042 commented May 30, 2025

Fixes #1006

  • unicode_variant_subtag applies to a single subtag, not a sequence
  • duplicate variant subtags must be rejected

@gibson042 gibson042 requested review from anba and sffc May 30, 2025 10:27
@gibson042 gibson042 force-pushed the gh-1006-locale-variants-validation branch from b3ab8c9 to ef5afed Compare May 30, 2025 10:28
Copy link
Copy Markdown
Contributor

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Thanks

Comment thread spec/locale.html
1. If _variants_ is not *undefined*, then
1. If _variants_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
1. For each element _variant_ of StringSplitToList(_variants_, *"-"*), do
1. If _variant_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It appears that GetLocaleVariants for something like a-variant1-variant2 returns variant1-variant2 so this logic looks correct.

Comment thread spec/locale.html
1. Let _variants_ be ? GetOption(_options_, *"variants"*, ~string~, ~empty~, GetLocaleVariants(_baseName_)).
1. If _variants_ is not *undefined*, then
1. If _variants_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
1. For each element _variant_ of StringSplitToList(_variants_, *"-"*), do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

StringSplitToList requires that neither input is the empty string. So we either need to handle the case when variants is the empty String or, alternatively, check if the input restriction on StringSplitToList can be lifted.

@anba
Copy link
Copy Markdown
Contributor

anba commented May 30, 2025

Additionally a new step needs to be added between steps 15-16:

  1. Set newTag to the string-concatenation of newTag and allExtensions.
  2. If IsStructurallyValidLanguageTag(newTag) is false, throw a RangeError exception.
  3. Return newTag.

This is needed to handle the case when duplicate variant subtags are present. Like for example: new Intl.Locale("en", {variants: "spanglis-spanglis"}).

…struction

Fixes tc39#1006

* `unicode_variant_subtag` applies to a single subtag, not a sequence
* duplicate variant subtags must be rejected
@gibson042 gibson042 force-pushed the gh-1006-locale-variants-validation branch from ef5afed to d4f778b Compare May 30, 2025 16:38
@gibson042 gibson042 changed the title Editorial: Fix incorrect application of unicode_variant_subtag against a subtag sequence Editorial: Fix incorrect validation of variants for Intl.Locale construction May 30, 2025
@gibson042
Copy link
Copy Markdown
Member Author

Thank you for the thorough review, @anba.

@gibson042 gibson042 merged commit 1f315d5 into tc39:main May 30, 2025
2 checks passed
Comment thread spec/locale.html
1. If _variants_ is the empty String, throw a *RangeError* exception.
1. For each element _variant_ of StringSplitToList(_variants_, *"-"*), do
1. If _variant_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
1. If _variants_ contains any duplicate subtags, throw a *RangeError* exception.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we trust that readers know that subtags are to be compared case-insensitively? IsStructurallyValidLanguageTag explicitly converts to lower-case to ensure case-insensitive comparison.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, good point. Clarified in #1009.

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.

Variants getter should not throw on multiple variants

3 participants