-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for structurally invalid language tags in DisplayNames.prototype.of() #3844
Conversation
assert.throws(RangeError, function() { | ||
displayNames.of('en-u-hebrew'); | ||
}, 'invalid language id -- contains singleton'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why you think this is invalid? It looks to me like a valid Unicode locale identifier with unicode_language_id
"en" and Unicode locale extension sequence "-u-hebrew", which includes the attribute
"hebrew" and no keyword
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When type is "language", code has to be a valid unicode_language_id
. See 12.5.1. Although the string in question is a valid unicode_locale_id
, a unicode_language_id
can only contain unicode_language_subtag
, unicode_script_subtag
, unicode_region_subtag
, and unicode_variant_subtag
, so strings with singletons are necessarily invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though now that I'm looking at it: doesn't the test in 12.5.1.1.a duplicate the test in IsStructurallyValidLanguageTag? Seems like all it does is save having to do the ASCII-lowercase
at the start of IsStructurallyValidLanguageTag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When type is "language", code has to be a valid
unicode_language_id
. See 12.5.1. Although the string in question is a validunicode_locale_id
, aunicode_language_id
can only containunicode_language_subtag
,unicode_script_subtag
,unicode_region_subtag
, andunicode_variant_subtag
, so strings with singletons are necessarily invalid.
👍
Though now that I'm looking at it: doesn't the test in 12.5.1.1.a duplicate the test in IsStructurallyValidLanguageTag? Seems like all it does is save having to do the
ASCII-lowercase
at the start of IsStructurallyValidLanguageTag.
Let's see... CanonicalCodeForDisplayNames step 1.a ensures that the input is an isolated Unicode language identifier (i.e., a language subtag with optional script subtag or a script subtag, in either case optionally followed by a region subtag and/or any number of variant subtags but NOT by singleton subtags or any other subtags), and step 1.b ensures that it does not use backwards compatibility syntax (IsStructurallyValidLanguageTag step 3 rejecting e.g. "en_GB" and "root" and "Latn-DE" per the respective UTS #35 Part 1 Core, BCP 47 Conformance "backwards compatibility" bullet points) or contain duplicate variant subtags (IsStructurallyValidLanguageTag step 6 rejecting e.g. "de-1996-fonipa-1996") that would both pass the preceding syntax check. So I like the current state of ECMA-402 text, and also the coverage being added in this PR.
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
assert.throws(RangeError, function() { | ||
displayNames.of('enxx'); | ||
}, 'invalid language subtag (4 letters)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.throws(RangeError, function() { | |
displayNames.of('enxx'); | |
}, 'invalid language subtag (4 letters)'); | |
assert.throws(RangeError, function() { | |
displayNames.of('enxx'); | |
}, 'invalid language id - starts with a script subtag (4 letters)'); |
But actually, how does this differ from "tries to use backwards compatibility feature (bare script subtag)" below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, fair! let me take that one out...
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
Thanks so much for working on these! ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few message consistency suggestions and assertion tweaks, but this looks good. Thanks again!
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
test/intl402/DisplayNames/prototype/of/type-language-invalid.js
Outdated
Show resolved
Hide resolved
a. If code cannot be matched by the unicode_language_id Unicode locale nonterminal, throw a RangeError exception. | ||
b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception. | ||
c. Return CanonicalizeUnicodeLocaleId(code). | ||
features: [Intl.DisplayNames-v2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Does this test actually use any features from Intl.DisplayNames-v2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops -- fixed!
3e51ef9
to
5cd229f
Compare
Co-authored-by: Richard Gibson <[email protected]>
5cd229f
to
34e77d1
Compare
All comments seem to have been addressed and we have an approval from Richard; I gave it a quick look additionally and it looks good. Merging now, sorry for the long wait. |
Previously no test coverage for cases where {type: 'language'}, created tests for structurally invalid tags.
fix #3840