Editorial: Fix incorrect validation of variants for Intl.Locale construction#1007
Conversation
b3ab8c9 to
ef5afed
Compare
| 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. |
There was a problem hiding this comment.
It appears that GetLocaleVariants for something like a-variant1-variant2 returns variant1-variant2 so this logic looks correct.
| 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 |
There was a problem hiding this comment.
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.
|
Additionally a new step needs to be added between steps 15-16:
This is needed to handle the case when duplicate variant subtags are present. Like for example: |
…struction Fixes tc39#1006 * `unicode_variant_subtag` applies to a single subtag, not a sequence * duplicate variant subtags must be rejected
ef5afed to
d4f778b
Compare
unicode_variant_subtag against a subtag sequencevariants for Intl.Locale construction
|
Thank you for the thorough review, @anba. |
| 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. |
There was a problem hiding this comment.
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.

Fixes #1006
unicode_variant_subtagapplies to a single subtag, not a sequence