Skip to content

Commit 210b1dc

Browse files
committed
[JSC] Intl.Collator's ignorePunctuation should reflect queried result
https://bugs.webkit.org/show_bug.cgi?id=263313 rdar://117122647 Reviewed by Alexey Shvayka. For example, th locale's ignorePunctuation is true by default. We should construct Intl.Collator, querying ignorePunctuation to the created ICU's collator, and setting it as resolvedOptions().ignorePunctuation. * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/runtime/IntlCollator.cpp: (JSC::IntlCollator::initializeCollator): Canonical link: https://commits.webkit.org/269459@main
1 parent 83cd481 commit 210b1dc

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

JSTests/test262/expectations.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,6 @@ test/harness/verifyProperty-desc-is-not-object.js:
10961096
test/harness/verifyProperty-value-error.js:
10971097
default: 'Error: The error thrown did not define the specified message.'
10981098
strict mode: 'Error: The error thrown did not define the specified message.'
1099-
test/intl402/Collator/prototype/compare/ignorePunctuation.js:
1100-
default: 'Test262Error: Compare to space Expected SameValue(«0», «-1») to be true'
1101-
strict mode: 'Test262Error: Compare to space Expected SameValue(«0», «-1») to be true'
11021099
test/intl402/DateTimeFormat/prototype/format/offset-timezone-gmt-same.js:
11031100
default: 'RangeError: invalid time zone: +0300'
11041101
strict mode: 'RangeError: invalid time zone: +0300'

Source/JavaScriptCore/runtime/IntlCollator.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ void IntlCollator::initializeCollator(JSGlobalObject* globalObject, JSValue loca
203203

204204
TriState ignorePunctuation = intlBooleanOption(globalObject, options, vm.propertyNames->ignorePunctuation);
205205
RETURN_IF_EXCEPTION(scope, void());
206-
m_ignorePunctuation = (ignorePunctuation == TriState::True);
207206

208207
// UCollator does not offer an option to configure "usage" via ucol_setAttribute. So we need to pass this option via locale.
209208
CString dataLocaleWithExtensions;
@@ -266,12 +265,19 @@ void IntlCollator::initializeCollator(JSGlobalObject* globalObject, JSValue loca
266265

267266
// FIXME: Setting UCOL_ALTERNATE_HANDLING to UCOL_SHIFTED causes punctuation and whitespace to be
268267
// ignored. There is currently no way to ignore only punctuation.
269-
ucol_setAttribute(m_collator.get(), UCOL_ALTERNATE_HANDLING, m_ignorePunctuation ? UCOL_SHIFTED : UCOL_DEFAULT, &status);
268+
if (ignorePunctuation != TriState::Indeterminate)
269+
ucol_setAttribute(m_collator.get(), UCOL_ALTERNATE_HANDLING, ignorePunctuation == TriState::True ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status);
270270

271271
// "The method is required to return 0 when comparing Strings that are considered canonically
272272
// equivalent by the Unicode standard."
273273
ucol_setAttribute(m_collator.get(), UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
274274
ASSERT(U_SUCCESS(status));
275+
276+
{
277+
auto result = ucol_getAttribute(m_collator.get(), UCOL_ALTERNATE_HANDLING, &status);
278+
ASSERT(U_SUCCESS(status));
279+
m_ignorePunctuation = (result == UCOL_SHIFTED);
280+
}
275281
}
276282

277283
// https://tc39.es/ecma402/#sec-collator-comparestrings

0 commit comments

Comments
 (0)