Changeset 264382 in webkit


Ignore:
Timestamp:
Jul 14, 2020, 4:36:58 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

REGRESSION(r262341) URL::createCFURL should produce a CFURL that uses UTF-8 to decode its percent-encoded sequences
https://bugs.webkit.org/show_bug.cgi?id=214314
<rdar://problem/65079249>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-07-14
Reviewed by Darin Adler.

Source/WTF:

r262341 made it so we usually pass kCFStringEncodingISOLatin1 into CFURLCreateAbsoluteURLWithBytes when creating a CFURLRef from a WTF::URL.
This is correct for the interpretation of the bytes to create a CFStringRef, and that is a change we want to make.
The encoding, however, is also stored with the CFURL and used later when interpreting percent-encoded sequences.
We want to use kCFStringEncodingUTF8 to make the interpretation of percent-encoded sequences the same as it used to be.
To avoid making a separate CString most of the time, use characters8() only for ASCII-only URLs, where UTF-8 and Latin1 are the same.
For all other URLs, we have to make a CString containing the UTF-8 representation of the string to get the percent-encoded sequences interpreted the same.

  • wtf/cf/URLCF.cpp:

(WTF::URL::createCFURL const):

  • wtf/cocoa/URLCocoa.mm:

(WTF::URL::createCFURL const):

Tools:

  • TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:

Add a direct test and update the Mojave test expectations for the test introduced in r262341 with the change that introduced this regression.

  • TestWebKitAPI/Tests/WebKitCocoa/LoadInvalidURLRequest.mm:

Update a test from r263475 which fixed another regression from r262341.
The test verified that nothing crashed or timed out, and that is still the case even with this intentional change in behavior.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r264367 r264382  
     12020-07-14  Alex Christensen  <achristensen@webkit.org>
     2
     3        REGRESSION(r262341) URL::createCFURL should produce a CFURL that uses UTF-8 to decode its percent-encoded sequences
     4        https://bugs.webkit.org/show_bug.cgi?id=214314
     5        <rdar://problem/65079249>
     6
     7        Reviewed by Darin Adler.
     8
     9        r262341 made it so we usually pass kCFStringEncodingISOLatin1 into CFURLCreateAbsoluteURLWithBytes when creating a CFURLRef from a WTF::URL.
     10        This is correct for the interpretation of the bytes to create a CFStringRef, and that is a change we want to make.
     11        The encoding, however, is also stored with the CFURL and used later when interpreting percent-encoded sequences.
     12        We want to use kCFStringEncodingUTF8 to make the interpretation of percent-encoded sequences the same as it used to be.
     13        To avoid making a separate CString most of the time, use characters8() only for ASCII-only URLs, where UTF-8 and Latin1 are the same.
     14        For all other URLs, we have to make a CString containing the UTF-8 representation of the string to get the percent-encoded sequences interpreted the same.
     15
     16        * wtf/cf/URLCF.cpp:
     17        (WTF::URL::createCFURL const):
     18        * wtf/cocoa/URLCocoa.mm:
     19        (WTF::URL::createCFURL const):
     20
    1212020-07-14  Jer Noble  <jer.noble@apple.com>
    222
  • trunk/Source/WTF/wtf/cf/URLCF.cpp

    r262341 r264382  
    5252{
    5353    RetainPtr<CFURLRef> cfURL;
    54     if (LIKELY(m_string.is8Bit()))
    55         cfURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, reinterpret_cast<const UInt8*>(m_string.characters8()), m_string.length(), kCFStringEncodingISOLatin1, nullptr, true));
     54    if (LIKELY(m_string.is8Bit() && m_string.isAllASCII()))
     55        cfURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, reinterpret_cast<const UInt8*>(m_string.characters8()), m_string.length(), kCFStringEncodingUTF8, nullptr, true));
    5656    else {
    5757        CString utf8 = m_string.utf8();
  • trunk/Source/WTF/wtf/cocoa/URLCocoa.mm

    r262341 r264382  
    7070
    7171    RetainPtr<CFURLRef> cfURL;
    72     if (LIKELY(m_string.is8Bit()))
    73         cfURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, reinterpret_cast<const UInt8*>(m_string.characters8()), m_string.length(), kCFStringEncodingISOLatin1, nullptr, true));
     72    if (LIKELY(m_string.is8Bit() && m_string.isAllASCII()))
     73        cfURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, reinterpret_cast<const UInt8*>(m_string.characters8()), m_string.length(), kCFStringEncodingUTF8, nullptr, true));
    7474    else {
    7575        CString utf8 = m_string.utf8();
  • trunk/Tools/ChangeLog

    r264376 r264382  
     12020-07-14  Alex Christensen  <achristensen@webkit.org>
     2
     3        REGRESSION(r262341) URL::createCFURL should produce a CFURL that uses UTF-8 to decode its percent-encoded sequences
     4        https://bugs.webkit.org/show_bug.cgi?id=214314
     5        <rdar://problem/65079249>
     6
     7        Reviewed by Darin Adler.
     8
     9        * TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
     10        Add a direct test and update the Mojave test expectations for the test introduced in r262341 with the change that introduced this regression.
     11        * TestWebKitAPI/Tests/WebKitCocoa/LoadInvalidURLRequest.mm:
     12        Update a test from r263475 which fixed another regression from r262341.
     13        The test verified that nothing crashed or timed out, and that is still the case even with this intentional change in behavior.
     14
    1152020-07-14  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm

    r262341 r264382  
    219219    EXPECT_FALSE(url4.isValid());
    220220    EXPECT_TRUE(url4.string().is8Bit());
    221 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101500
    222     // CFURLCreateAbsoluteURLWithBytes has incorrect behavior on Mojave
    223     // See https://bugs.webkit.org/show_bug.cgi?id=212486#c6
    224     EXPECT_STREQ([[url4 absoluteString] UTF8String], "%C2%B6");
    225 #else
    226221    EXPECT_STREQ([[url4 absoluteString] UTF8String], "%C3%82%C2%B6");
    227 #endif
     222
     223    char buffer[100];
     224    memset(buffer, 0, sizeof(buffer));
     225    WTF::URL url5(URL(), "file:///A%C3%A7%C3%A3o.html"_s);
     226    CFURLGetFileSystemRepresentation(url5.createCFURL().get(), false, reinterpret_cast<UInt8*>(buffer), sizeof(buffer));
     227    EXPECT_STREQ(buffer, "/Ação.html");
    228228}
    229229
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadInvalidURLRequest.mm

    r263475 r264382  
    9494        EXPECT_WK_STREQ(error.domain, @"WebKitErrorDomain");
    9595        EXPECT_EQ(error.code, WebKitErrorCannotShowURL);
    96         EXPECT_WK_STREQ([error.userInfo[@"NSErrorFailingURLKey"] absoluteString], "http://%E2%80%80");
     96        EXPECT_WK_STREQ([error.userInfo[@"NSErrorFailingURLKey"] absoluteString], "http://%C3%A2%C2%80%C2%80");
    9797        done = true;
    9898    };
Note: See TracChangeset for help on using the changeset viewer.