Changeset 274784 in webkit


Ignore:
Timestamp:
Mar 22, 2021 1:07:23 PM (16 months ago)
Author:
ysuzuki@apple.com
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/JavaScriptCore:

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):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r274727 r274784  
     12021-03-22  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Intl.Locale should not assume is8Bit
     4        https://bugs.webkit.org/show_bug.cgi?id=223553
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * stress/intl-locale-non-8bit.js: Added.
     9        (shouldBe):
     10
    1112021-03-19  Mark Lam  <mark.lam@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r274770 r274784  
     12021-03-22  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Intl.Locale should not assume is8Bit
     4        https://bugs.webkit.org/show_bug.cgi?id=223553
     5
     6        Reviewed by Ross Kirsling.
     7
     8        is8Bit or not is not guaranteed if it is an user-input. For example, "test日本語".substring(0, 3) should be non 8Bit string.
     9        Intl.Locale has several places that assumed that input should be 8Bit if they are ASCII. This patch fixes it.
     10
     11        * runtime/IntlLocale.cpp:
     12        (JSC::LocaleIDBuilder::overrideLanguageScriptRegion):
     13        (JSC::LocaleIDBuilder::setKeywordValue):
     14
    1152021-03-22  Sam Weinig  <weinig@apple.com>
    216
  • trunk/Source/JavaScriptCore/runtime/IntlLocale.cpp

    r273187 r274784  
    151151            hasAppended = true;
    152152
    153         ASSERT(subtag.is8Bit() && subtag.isAllASCII());
    154         buffer.append(reinterpret_cast<const char*>(subtag.characters8()), subtag.length());
     153        ASSERT(subtag.isAllASCII());
     154        if (subtag.is8Bit())
     155            buffer.append(subtag.characters8(), subtag.length());
     156        else
     157            buffer.append(subtag.characters16(), subtag.length());
    155158    }
    156159
     
    158161        auto rest = localeIDView.right(length - endOfLanguageScriptRegionVariant);
    159162
    160         ASSERT(rest.is8Bit() && rest.isAllASCII());
    161         buffer.append(reinterpret_cast<const char*>(rest.characters8()), rest.length());
     163        ASSERT(rest.isAllASCII());
     164        if (rest.is8Bit())
     165            buffer.append(rest.characters8(), rest.length());
     166        else
     167            buffer.append(rest.characters16(), rest.length());
    162168    }
    163169
     
    170176    ASSERT(m_buffer.size());
    171177
    172     ASSERT(value.is8Bit() && value.isAllASCII());
    173     CString rawValue { reinterpret_cast<const char*>(value.characters8()), value.length() };
     178    ASSERT(value.isAllASCII());
     179    Vector<char, 32> rawValue(value.length() + 1);
     180    if (value.is8Bit())
     181        StringImpl::copyCharacters(reinterpret_cast<LChar*>(rawValue.data()), value.characters8(), value.length());
     182    else
     183        StringImpl::copyCharacters(reinterpret_cast<LChar*>(rawValue.data()), value.characters16(), value.length());
     184    rawValue[value.length()] = '\0';
    174185
    175186    UErrorCode status = U_ZERO_ERROR;
Note: See TracChangeset for help on using the changeset viewer.