Changeset 14217 in webkit


Ignore:
Timestamp:
May 7, 2006 11:01:59 AM (18 years ago)
Author:
ap
Message:

Reviewed by Darin.

Tests:

  • fast/forms/form-data-encoding.html
  • fast/forms/form-data-encoding-2.html
  • platform/mac/TextEncodingMac.cpp: (WebCore::TextEncoding::fromUnicode): Normalize the string; handle surrogate pairs.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r14211 r14217  
     12006-05-07  Alexey Proskuryakov  <ap@nypop.com>
     2
     3        Reviewed by Darin.
     4
     5        - Tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=8769
     6          TextEncoding::fromUnicode() - support non-BMP characters and convert to NFC
     7
     8        * fast/forms/form-data-encoding.html: Cover more cases for Latin-1 encoding.
     9        * fast/forms/form-data-encoding-2.html: Added. Test conversion to UTF-8.
     10        * fast/forms/form-data-encoding-2-expected.txt: Added.
     11
    1122006-05-05  Alexey Proskuryakov  <ap@nypop.com>
    213
  • trunk/LayoutTests/fast/forms/form-data-encoding.html

    r11995 r14217  
    66<body>
    77<form action="?" name=f>
    8  <input type=hidden name=q value="&#1090;&#1077;&#1089;&#1090;"><br>
     8 <input type=hidden name=q value="&#1105;&#66560;&#119083;çc"><br>
    99</form>
    1010<script>
    1111if (window.layoutTestController) {
    12         layoutTestController.dumpAsText();
    13         layoutTestController.waitUntilDone();
     12    layoutTestController.dumpAsText();
     13    layoutTestController.waitUntilDone();
    1414}
    1515
    1616if (document.URL.substring(0, 4) == "file") {
    1717
    18         if (document.URL.indexOf('?') == -1) {
     18    if (document.URL.indexOf('?') == -1) {
     19        document.f.q.value += "\u0327"; // cedilla for 'c'
     20        document.f.submit();
    1921
    20                 document.f.submit();
    21 
    22         } else {
    23                
    24                 if (unescape(document.URL.substring(document.URL.indexOf('?')+1, document.URL.length)) == unescape("q=%26%231090%3B%26%231077%3B%26%231089%3B%26%231090%3B"))
    25                         document.write("<p>Success</p>");
    26                 else
    27                         document.write("<p>Failure</p>");
    28                
    29                 if (window.layoutTestController)
    30                         layoutTestController.notifyDone();
    31         }
     22    } else {
     23        if (unescape(document.URL.substring(document.URL.indexOf('?')+1, document.URL.length)) == unescape("q=%26%231105%3B%26%2366560%3B%26%23119083%3B%E7%E7"))
     24            document.write("<p>Success</p>");
     25        else
     26            document.write("<p>Failure</p>");
     27       
     28        if (window.layoutTestController)
     29            layoutTestController.notifyDone();
     30    }
    3231
    3332} else {
    3433
    35         document.write("<p>This test doesn't work directly from bugzilla, please save it to a local file first.</p>");
     34    document.write("<p>This test doesn't work directly from bugzilla, please save it to a local file first.</p>");
    3635}
    3736</script>
  • trunk/WebCore/ChangeLog

    r14216 r14217  
     12006-05-07  Alexey Proskuryakov  <ap@nypop.com>
     2
     3        Reviewed by Darin.
     4
     5        - http://bugzilla.opendarwin.org/show_bug.cgi?id=8769
     6          TextEncoding::fromUnicode() - support non-BMP characters and convert to NFC
     7
     8        Tests:
     9        * fast/forms/forms/form-data-encoding.html
     10        * fast/forms/forms/form-data-encoding-2.html
     11
     12        * platform/mac/TextEncodingMac.cpp:
     13        (WebCore::TextEncoding::fromUnicode): Normalize the string; handle surrogate pairs.
     14
    1152006-05-06  David Hyatt  <hyatt@apple.com>
    216
  • trunk/WebCore/platform/mac/TextEncodingMac.cpp

    r13901 r14217  
    5454    copy.replace(QChar('\\'), backslashAsCurrencySymbol());
    5555    CFStringRef cfs = copy.getCFString();
     56    CFMutableStringRef cfms = CFStringCreateMutableCopy(0, 0, cfs); // in rare cases, normalization can make the string longer, thus no limit on its length
     57    CFStringNormalize(cfms, kCFStringNormalizationFormC);
    5658   
    5759    CFIndex startPos = 0;
    58     CFIndex charactersLeft = CFStringGetLength(cfs);
    59     DeprecatedCString result(1); // for trailng zero
     60    CFIndex charactersLeft = CFStringGetLength(cfms);
     61    DeprecatedCString result(1); // for trailing zero
    6062
    6163    while (charactersLeft > 0) {
    6264        CFRange range = CFRangeMake(startPos, charactersLeft);
    6365        CFIndex bufferLength;
    64         CFStringGetBytes(cfs, range, encoding, allowEntities ? 0 : '?', false, NULL, 0x7FFFFFFF, &bufferLength);
     66        CFStringGetBytes(cfms, range, encoding, allowEntities ? 0 : '?', false, NULL, 0x7FFFFFFF, &bufferLength);
    6567       
    6668        DeprecatedCString chunk(bufferLength + 1);
    6769        unsigned char *buffer = reinterpret_cast<unsigned char *>(chunk.data());
    68         CFIndex charactersConverted = CFStringGetBytes(cfs, range, encoding, allowEntities ? 0 : '?', false, buffer, bufferLength, &bufferLength);
     70        CFIndex charactersConverted = CFStringGetBytes(cfms, range, encoding, allowEntities ? 0 : '?', false, buffer, bufferLength, &bufferLength);
    6971        buffer[bufferLength] = 0;
    7072        result.append(chunk);
    7173       
    7274        if (charactersConverted != charactersLeft) {
    73             // FIXME: support surrogate pairs
    74             UniChar badChar = CFStringGetCharacterAtIndex(cfs, startPos + charactersConverted);
     75            unsigned int badChar = CFStringGetCharacterAtIndex(cfms, startPos + charactersConverted);
     76            ++charactersConverted;
     77
     78            if ((badChar & 0xfc00) == 0xd800 &&     // is high surrogate
     79                  charactersConverted != charactersLeft) {
     80                UniChar low = CFStringGetCharacterAtIndex(cfms, startPos + charactersConverted);
     81                if ((low & 0xfc00) == 0xdc00) {     // is low surrogate
     82                    badChar <<= 10;
     83                    badChar += low;
     84                    badChar += 0x10000 - (0xd800 << 10) - 0xdc00;
     85                    ++charactersConverted;
     86                }
     87            }
    7588            char buf[16];
    7689            sprintf(buf, "&#%u;", badChar);
    7790            result.append(buf);
    78            
    79             ++charactersConverted;
    8091        }
    8192       
     
    8394        charactersLeft -= charactersConverted;
    8495    }
     96    CFRelease(cfms);
    8597    return result;
    8698}
Note: See TracChangeset for help on using the changeset viewer.