mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 11:57:35 +00:00
LibJS: Compare Unicode locale variants using case-insensitive matching
In the IsStructurallyValidLanguageTag AO, we of course cannot assume the variants are canonicalized to lower-case yet, because canonicalization hasn't happened yet.
This commit is contained in:
parent
fdedb3ab33
commit
940c023e09
2 changed files with 8 additions and 1 deletions
|
@ -26,7 +26,7 @@ static Optional<Unicode::LocaleID> is_structurally_valid_language_tag(StringView
|
||||||
quick_sort(variants);
|
quick_sort(variants);
|
||||||
|
|
||||||
for (size_t i = 0; i < variants.size() - 1; ++i) {
|
for (size_t i = 0; i < variants.size() - 1; ++i) {
|
||||||
if (variants[i] == variants[i + 1])
|
if (variants[i].equals_ignoring_case(variants[i + 1]))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,13 @@ describe("errors", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("duplicate variant subtags", () => {
|
test("duplicate variant subtags", () => {
|
||||||
|
expect(() => {
|
||||||
|
Intl.getCanonicalLocales("en-posix-POSIX");
|
||||||
|
}).toThrowWithMessage(
|
||||||
|
RangeError,
|
||||||
|
"en-posix-POSIX is not a structurally valid language tag"
|
||||||
|
);
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Intl.getCanonicalLocales("en-POSIX-POSIX");
|
Intl.getCanonicalLocales("en-POSIX-POSIX");
|
||||||
}).toThrowWithMessage(
|
}).toThrowWithMessage(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue