⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 201863 in webkit


Ignore:
Timestamp:
Jun 9, 2016, 7:54:50 AM (10 years ago)
Author:
msaboff@apple.com
Message:

WebKitTestRunner and DumpRenderTree do not handle dangling surrogate characters
https://bugs.webkit.org/show_bug.cgi?id=154863

Reviewed by Alexey Proskuryakov.

Source/WebKit2:

Added a non-strict verions of WKStringGetUTF8CString() that will handle dangling
surrogates called WKStringGetUTF8CStringNonStrict().

  • Shared/API/c/WKString.cpp:

(WKStringGetUTF8CStringImpl):
(WKStringGetUTF8CString):
(WKStringGetUTF8CStringNonStrict):

  • Shared/API/c/WKString.h:

Tools:

Added a non-strict verions of WKStringGetUTF8CString() that will handle dangling
surrogates. Changed the extraction of inner text from frames in DumpRenderTree
to use the new WKStringGetUTF8CStringNonStrict() function instead of NSString
conversion since NSString doesn't have a way to handle dangling surrogates.
The code added in DumpRenderTree matches what was changed in WebKitTestRunner.

  • DumpRenderTree/mac/DumpRenderTree.mm:

(dumpFramesAsText):

  • WebKitTestRunner/StringFunctions.h:

(WTR::toWTFString):

LayoutTests:

New tests.

  • fast/text/dangling-surrogates-expected.txt: Added.
  • fast/text/dangling-surrogates.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201861 r201863  
     12016-06-09  Michael Saboff  <msaboff@apple.com>
     2
     3        WebKitTestRunner and DumpRenderTree do not handle dangling surrogate characters
     4        https://bugs.webkit.org/show_bug.cgi?id=154863
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        New tests.
     9
     10        * fast/text/dangling-surrogates-expected.txt: Added.
     11        * fast/text/dangling-surrogates.html: Added.
     12
    1132016-06-09  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/Source/WebKit2/ChangeLog

    r201860 r201863  
     12016-06-09  Michael Saboff  <msaboff@apple.com>
     2
     3        WebKitTestRunner and DumpRenderTree do not handle dangling surrogate characters
     4        https://bugs.webkit.org/show_bug.cgi?id=154863
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Added a non-strict verions of WKStringGetUTF8CString() that will handle dangling
     9        surrogates called WKStringGetUTF8CStringNonStrict().
     10
     11        * Shared/API/c/WKString.cpp:
     12        (WKStringGetUTF8CStringImpl):
     13        (WKStringGetUTF8CString):
     14        (WKStringGetUTF8CStringNonStrict):
     15        * Shared/API/c/WKString.h:
     16
    1172016-06-09  Carlos Garcia Campos  <cgarcia@igalia.com>
    218
  • trunk/Source/WebKit2/Shared/API/c/WKString.cpp

    r195743 r201863  
    7171}
    7272
    73 size_t WKStringGetUTF8CString(WKStringRef stringRef, char* buffer, size_t bufferSize)
     73enum StrictType { NonStrict = false, Strict = true };
     74
     75template <StrictType strict>
     76size_t WKStringGetUTF8CStringImpl(WKStringRef stringRef, char* buffer, size_t bufferSize)
    7477{
    7578    if (!bufferSize)
     
    8689    } else {
    8790        const UChar* characters = stringView.characters16();
    88         result = WTF::Unicode::convertUTF16ToUTF8(&characters, characters + stringView.length(), &p, p + bufferSize - 1, /* strict */ true);
     91        result = WTF::Unicode::convertUTF16ToUTF8(&characters, characters + stringView.length(), &p, p + bufferSize - 1, strict);
    8992    }
    9093
     
    9497    *p++ = '\0';
    9598    return p - buffer;
     99}
     100
     101size_t WKStringGetUTF8CString(WKStringRef stringRef, char* buffer, size_t bufferSize)
     102{
     103    return WKStringGetUTF8CStringImpl<StrictType::Strict>(stringRef, buffer, bufferSize);
     104}
     105
     106size_t WKStringGetUTF8CStringNonStrict(WKStringRef stringRef, char* buffer, size_t bufferSize)
     107{
     108    return WKStringGetUTF8CStringImpl<StrictType::NonStrict>(stringRef, buffer, bufferSize);
    96109}
    97110
  • trunk/Source/WebKit2/Shared/API/c/WKString.h

    r168541 r201863  
    5656WK_EXPORT size_t WKStringGetMaximumUTF8CStringSize(WKStringRef string);
    5757WK_EXPORT size_t WKStringGetUTF8CString(WKStringRef string, char* buffer, size_t bufferSize);
     58WK_EXPORT size_t WKStringGetUTF8CStringNonStrict(WKStringRef string, char* buffer, size_t bufferSize);
    5859
    5960WK_EXPORT bool WKStringIsEqual(WKStringRef a, WKStringRef b);
  • trunk/Tools/ChangeLog

    r201849 r201863  
     12016-06-09  Michael Saboff  <msaboff@apple.com>
     2
     3        WebKitTestRunner and DumpRenderTree do not handle dangling surrogate characters
     4        https://bugs.webkit.org/show_bug.cgi?id=154863
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Added a non-strict verions of WKStringGetUTF8CString() that will handle dangling
     9        surrogates.  Changed the extraction of inner text from frames in DumpRenderTree
     10        to use the new WKStringGetUTF8CStringNonStrict() function instead of NSString
     11        conversion since NSString doesn't have a way to handle dangling surrogates.
     12        The code added in DumpRenderTree matches what was changed in WebKitTestRunner.
     13
     14        * DumpRenderTree/mac/DumpRenderTree.mm:
     15        (dumpFramesAsText):
     16        * WebKitTestRunner/StringFunctions.h:
     17        (WTR::toWTFString):
     18
    1192016-06-08  Hunseop Jeong  <hs85.jeong@samsung.com>
    220
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r201404 r201863  
    6363#import <WebKit/DOMExtensions.h>
    6464#import <WebKit/DOMRange.h>
     65#import <WebKit/WKString.h>
     66#import <WebKit/WKStringCF.h>
    6567#import <WebKit/WebArchive.h>
    6668#import <WebKit/WebBackForwardList.h>
     
    15241526        result = [NSMutableString stringWithFormat:@"\n--------\nFrame: '%@'\n--------\n", [frame name]];
    15251527
    1526     [result appendFormat:@"%@\n", [documentElement innerText]];
     1528    NSString *innerText = [documentElement innerText];
     1529    // We use WKStringGetUTF8CStringNonStrict() to convert innerText to a WK String since
     1530    // WKStringGetUTF8CStringNonStrict() can handle dangling surrogates and the NSString
     1531    // conversion methods cannot. After the conversion to a buffer, we turn that buffer into
     1532    // a CFString via fromUTF8WithLatin1Fallback().createCFString() which can be appended to
     1533    // the result without any conversion.
     1534    WKStringRef stringRef = WKStringCreateWithCFString((CFStringRef)innerText);
     1535    size_t bufferSize = WKStringGetMaximumUTF8CStringSize(stringRef);
     1536    auto buffer = std::make_unique<char[]>(bufferSize);
     1537    size_t stringLength = WKStringGetUTF8CStringNonStrict(stringRef, buffer.get(), bufferSize);
     1538    [result appendFormat:@"%@\n", String::fromUTF8WithLatin1Fallback(buffer.get(), stringLength - 1).createCFString().get()];
    15271539
    15281540    if (gTestRunner->dumpChildFramesAsText()) {
  • trunk/Tools/WebKitTestRunner/StringFunctions.h

    r168961 r201863  
    8888    size_t bufferSize = WKStringGetMaximumUTF8CStringSize(string);
    8989    auto buffer = std::make_unique<char[]>(bufferSize);
    90     size_t stringLength = WKStringGetUTF8CString(string, buffer.get(), bufferSize);
     90    size_t stringLength = WKStringGetUTF8CStringNonStrict(string, buffer.get(), bufferSize);
    9191    return WTF::String::fromUTF8WithLatin1Fallback(buffer.get(), stringLength - 1);
    9292}
Note: See TracChangeset for help on using the changeset viewer.