Title: [274784] trunk
Revision
274784
Author
[email protected]
Date
2021-03-22 13:07:23 -0700 (Mon, 22 Mar 2021)

Log Message

[JSC] Intl.Locale should not assume is8Bit
https://bugs.webkit.org/show_bug.cgi?id=223553

Reviewed by Ross Kirsling.

JSTests:

* stress/intl-locale-non-8bit.js: Added.
(shouldBe):

Source/_javascript_Core:

is8Bit or not is not guaranteed if it is an user-input. For example, "test日本語".substring(0, 3) should be non 8Bit string.
Intl.Locale has several places that assumed that input should be 8Bit if they are ASCII. This patch fixes it.

* runtime/IntlLocale.cpp:
(JSC::LocaleIDBuilder::overrideLanguageScriptRegion):
(JSC::LocaleIDBuilder::setKeywordValue):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (274783 => 274784)


--- trunk/JSTests/ChangeLog	2021-03-22 19:55:32 UTC (rev 274783)
+++ trunk/JSTests/ChangeLog	2021-03-22 20:07:23 UTC (rev 274784)
@@ -1,3 +1,13 @@
+2021-03-22  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Intl.Locale should not assume is8Bit
+        https://bugs.webkit.org/show_bug.cgi?id=223553
+
+        Reviewed by Ross Kirsling.
+
+        * stress/intl-locale-non-8bit.js: Added.
+        (shouldBe):
+
 2021-03-19  Mark Lam  <[email protected]>
 
         BrandedStructure should keep its members alive.

Added: trunk/JSTests/stress/intl-locale-non-8bit.js (0 => 274784)


--- trunk/JSTests/stress/intl-locale-non-8bit.js	                        (rev 0)
+++ trunk/JSTests/stress/intl-locale-non-8bit.js	2021-03-22 20:07:23 UTC (rev 274784)
@@ -0,0 +1,18 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error(`expected ${expected} but got ${actual}`);
+}
+
+const options = {
+    calendar: 'buddhist',
+    caseFirst: 'lower',
+    collation: 'eor日本語'.substring(0, 3),
+    hourCycle: 'h11',
+    numeric: false,
+    numberingSystem: 'thai',
+    language: 'ja',
+    script: 'Hant',
+    region: 'KR'
+};
+const expected = 'ja-Hant-KR-u-ca-buddhist-co-eor-hc-h11-kf-lower-kn-false-nu-thai';
+shouldBe(new Intl.Locale('en', options).toString(), expected);

Modified: trunk/Source/_javascript_Core/ChangeLog (274783 => 274784)


--- trunk/Source/_javascript_Core/ChangeLog	2021-03-22 19:55:32 UTC (rev 274783)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-03-22 20:07:23 UTC (rev 274784)
@@ -1,3 +1,17 @@
+2021-03-22  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Intl.Locale should not assume is8Bit
+        https://bugs.webkit.org/show_bug.cgi?id=223553
+
+        Reviewed by Ross Kirsling.
+
+        is8Bit or not is not guaranteed if it is an user-input. For example, "test日本語".substring(0, 3) should be non 8Bit string.
+        Intl.Locale has several places that assumed that input should be 8Bit if they are ASCII. This patch fixes it.
+
+        * runtime/IntlLocale.cpp:
+        (JSC::LocaleIDBuilder::overrideLanguageScriptRegion):
+        (JSC::LocaleIDBuilder::setKeywordValue):
+
 2021-03-22  Sam Weinig  <[email protected]>
 
         Use the PropertyName parameter passed to custom getters/setters rather than a redundant const char* in DOM attribute prologues

Modified: trunk/Source/_javascript_Core/runtime/IntlLocale.cpp (274783 => 274784)


--- trunk/Source/_javascript_Core/runtime/IntlLocale.cpp	2021-03-22 19:55:32 UTC (rev 274783)
+++ trunk/Source/_javascript_Core/runtime/IntlLocale.cpp	2021-03-22 20:07:23 UTC (rev 274784)
@@ -150,15 +150,21 @@
         else
             hasAppended = true;
 
-        ASSERT(subtag.is8Bit() && subtag.isAllASCII());
-        buffer.append(reinterpret_cast<const char*>(subtag.characters8()), subtag.length());
+        ASSERT(subtag.isAllASCII());
+        if (subtag.is8Bit())
+            buffer.append(subtag.characters8(), subtag.length());
+        else
+            buffer.append(subtag.characters16(), subtag.length());
     }
 
     if (endOfLanguageScriptRegionVariant != length) {
         auto rest = localeIDView.right(length - endOfLanguageScriptRegionVariant);
 
-        ASSERT(rest.is8Bit() && rest.isAllASCII());
-        buffer.append(reinterpret_cast<const char*>(rest.characters8()), rest.length());
+        ASSERT(rest.isAllASCII());
+        if (rest.is8Bit())
+            buffer.append(rest.characters8(), rest.length());
+        else
+            buffer.append(rest.characters16(), rest.length());
     }
 
     buffer.append('\0');
@@ -169,8 +175,13 @@
 {
     ASSERT(m_buffer.size());
 
-    ASSERT(value.is8Bit() && value.isAllASCII());
-    CString rawValue { reinterpret_cast<const char*>(value.characters8()), value.length() };
+    ASSERT(value.isAllASCII());
+    Vector<char, 32> rawValue(value.length() + 1);
+    if (value.is8Bit())
+        StringImpl::copyCharacters(reinterpret_cast<LChar*>(rawValue.data()), value.characters8(), value.length());
+    else
+        StringImpl::copyCharacters(reinterpret_cast<LChar*>(rawValue.data()), value.characters16(), value.length());
+    rawValue[value.length()] = '\0';
 
     UErrorCode status = U_ZERO_ERROR;
     auto length = uloc_setKeywordValue(key.characters(), rawValue.data(), m_buffer.data(), m_buffer.size(), &status);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to