Changeset 62155 in webkit


Ignore:
Timestamp:
Jun 29, 2010 6:16:21 PM (14 years ago)
Author:
kinuko@chromium.org
Message:

2010-06-29 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by Jian Li.

Fix http/tests/local/blob/send-data-blob.html on Windows
https://bugs.webkit.org/show_bug.cgi?id=41228

Fix a regression bug in the line-conversion code.
Rewrite the line-conversion function with simpler functions to
make it less error prone.

No new tests as this is for bug fixes.

  • platform/BlobItem.cpp: (WebCore::StringBlobItem::convertToCString):

2010-06-29 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by Jian Li.

Fix http/tests/local/blob/send-data-blob.html on Windows
https://bugs.webkit.org/show_bug.cgi?id=41228

Fix the cgi code to make it work with cygwin perl.
Also fix test expectations for Windows.

  • http/tests/resources/post-and-verify-hybrid.cgi:
  • platform/chromium/test_expectations.txt:
  • platform/win/fast/js/global-constructors-expected.txt:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r62154 r62155  
     12010-06-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by Jian Li.
     4
     5        Fix http/tests/local/blob/send-data-blob.html on Windows
     6        https://bugs.webkit.org/show_bug.cgi?id=41228
     7
     8        Fix the cgi code to make it work with cygwin perl.
     9        Also fix test expectations for Windows.
     10
     11        * http/tests/resources/post-and-verify-hybrid.cgi:
     12        * platform/chromium/test_expectations.txt:
     13        * platform/win/fast/js/global-constructors-expected.txt:
     14
    1152010-06-29  James Robinson  <jamesr@chromium.org>
    216
  • trunk/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi

    r61650 r62155  
    11#!/usr/bin/perl -w
     2
     3use Config;
    24
    35print "Content-type: text/plain\n\n";
     
    7173
    7274    if ($values{'convert_newlines'}) {
    73         $nativeEnding = ($^O =~ /MSWin/) ? "\r\n" : "\n";
     75        $nativeEnding = ($Config{osname} =~ /(MSWin|cygwin)/) ? "\r\n" : "\n";
    7476        $postData =~ s/$nativeEnding/[NL]/g;
    7577    }
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r62154 r62155  
    28772877BUG_HCLAM : fast/js/script-line-number.html = TEXT
    28782878
    2879 // Added by r61650
    2880 BUG47259 WIN : http/tests/local/blob/send-data-blob.html = TEXT
    2881 
    28822879// LayoutTestController::isPageBoxVisible, pageAreaRectInPixels, and preferredPageSizeInPixels are not implemented yet for Chromium.
    28832880BUGWK37538 : printing/page-format-data.html = TEXT
  • trunk/LayoutTests/platform/win/fast/js/global-constructors-expected.txt

    r61531 r62155  
    88PASS BeforeLoadEvent.toString() is '[object BeforeLoadEventConstructor]'
    99PASS Blob.toString() is '[object BlobConstructor]'
     10PASS BlobBuilder.toString() is '[object BlobBuilderConstructor]'
    1011PASS CDATASection.toString() is '[object CDATASectionConstructor]'
    1112PASS CSSCharsetRule.toString() is '[object CSSCharsetRuleConstructor]'
  • trunk/WebCore/ChangeLog

    r62153 r62155  
     12010-06-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by Jian Li.
     4
     5        Fix http/tests/local/blob/send-data-blob.html on Windows
     6        https://bugs.webkit.org/show_bug.cgi?id=41228
     7
     8        Fix a regression bug in the line-conversion code.
     9        Rewrite the line-conversion function with simpler functions to
     10        make it less error prone.
     11
     12        No new tests as this is for bug fixes.
     13
     14        * platform/BlobItem.cpp:
     15        (WebCore::StringBlobItem::convertToCString):
     16
    1172010-06-29  Dumitru Daniliuc  <dumi@chromium.org>
    218
  • trunk/WebCore/platform/BlobItem.cpp

    r61349 r62155  
    3434#include "FileSystem.h"
    3535#include "UUID.h"
     36#include <wtf/Assertions.h>
    3637
    3738namespace WebCore {
     
    125126}
    126127
     128// Normalize all line-endings to CRLF.
     129static CString convertToCRLF(const CString& from)
     130{
     131    unsigned newLen = 0;
     132    const char* p = from.data();
     133    while (char c = *p++) {
     134        if (c == '\r') {
     135            // Safe to look ahead because of trailing '\0'.
     136            if (*p != '\n') {
     137                // Turn CR into CRLF.
     138                newLen += 2;
     139            }
     140        } else if (c == '\n') {
     141            // Turn LF into CRLF.
     142            newLen += 2;
     143        } else {
     144            // Leave other characters alone.
     145            newLen += 1;
     146        }
     147    }
     148    if (newLen == from.length())
     149        return from;
     150
     151    // Make a copy of the string.
     152    p = from.data();
     153    char* q;
     154    CString result = CString::newUninitialized(newLen, q);
     155    while (char c = *p++) {
     156        if (c == '\r') {
     157            // Safe to look ahead because of trailing '\0'.
     158            if (*p != '\n') {
     159                // Turn CR into CRLF.
     160                *q++ = '\r';
     161                *q++ = '\n';
     162            }
     163        } else if (c == '\n') {
     164            // Turn LF into CRLF.
     165            *q++ = '\r';
     166            *q++ = '\n';
     167        } else {
     168            // Leave other characters alone.
     169            *q++ = c;
     170        }
     171    }
     172    return result;
     173}
     174
     175// Normalize all line-endings to CR or LF.
     176static CString convertToCROrLF(const CString& from, bool toCR)
     177{
     178    unsigned newLen = 0;
     179    bool needFix = false;
     180    const char* p = from.data();
     181    char fromEndingChar = toCR ? '\n' : '\r';
     182    char toEndingChar = toCR ? '\r' : '\n';
     183    while (char c = *p++) {
     184        if (c == '\r' && *p == '\n') {
     185            // Turn CRLF into CR or LF.
     186            p++;
     187            needFix = true;
     188        } else if (c == fromEndingChar) {
     189            // Turn CR/LF into LF/CR.
     190            needFix = true;
     191        }
     192        newLen += 1;
     193    }
     194    if (!needFix)
     195        return from;
     196
     197    // Make a copy of the string.
     198    p = from.data();
     199    char* q;
     200    CString result = CString::newUninitialized(newLen, q);
     201    while (char c = *p++) {
     202        if (c == '\r' && *p == '\n') {
     203            // Turn CRLF or CR into CR or LF.
     204            p++;
     205            *q++ = toEndingChar;
     206        } else if (c == fromEndingChar) {
     207            // Turn CR/LF into LF/CR.
     208            *q++ = toEndingChar;
     209        } else {
     210            // Leave other characters alone.
     211            *q++ = c;
     212        }
     213    }
     214    return result;
     215}
     216
    127217CString StringBlobItem::convertToCString(const String& text, LineEnding ending, TextEncoding encoding)
    128218{
    129219    CString from = encoding.encode(text.characters(), text.length(), EntitiesForUnencodables);
    130     CString result = from;
    131 
    132     if (ending == EndingTransparent)
    133         return result;
    134220
    135221    if (ending == EndingNative) {
     
    141227    }
    142228
    143     const char* endingChars = (ending == EndingCRLF) ? "\r\n" : ((ending == EndingCR) ? "\r" : "\n");
    144 
    145     int endingLength = (ending == EndingCRLF) ? 2 : 1;
    146     int needFix = 0;
    147 
    148     // Calculate the final length.
    149     int calculatedLength = from.length();
    150     const char* p = from.data();
    151     while (char c = *p++) {
    152         if (c == '\r') {
    153             // Safe to look ahead because of trailing '\0'.
    154             if (*p == '\n' && ending != EndingCRLF) {
    155                 p++;
    156                 calculatedLength += (endingLength - 2);
    157                 ++needFix;
    158             } else if (ending != EndingCR) {
    159                 calculatedLength += (endingLength - 1);
    160                 ++needFix;
    161             }
    162         } else if (c == '\n' && ending != EndingLF) {
    163             calculatedLength += (endingLength - 1);
    164             ++needFix;
    165         }
    166     }
    167 
    168     if (!needFix)
    169         return result;
    170 
    171     // Convert the endings and create a data buffer.
    172     p = from.data();
    173     char* q;
    174     result = CString::newUninitialized(calculatedLength, q);
    175     while (char c = *p++) {
    176         if (c == '\r') {
    177             if (*p == '\n' && ending != EndingCRLF) {
    178                 p++;
    179                 memcpy(q, endingChars, endingLength);
    180                 q += endingLength;
    181             } else if (*p != '\n' && ending != EndingCR) {
    182                 memcpy(q, endingChars, endingLength);
    183                 q += endingLength;
    184             }
    185         } else if (c == '\n' && ending != EndingLF) {
    186             memcpy(q, endingChars, endingLength);
    187             q += endingLength;
    188         } else {
    189             // Leave other characters alone.
    190             *q++ = c;
    191         }
    192     }
    193     return result;
     229    switch (ending) {
     230    case EndingTransparent:
     231        return from;
     232    case EndingCRLF:
     233        return convertToCRLF(from);
     234    case EndingCR:
     235        return convertToCROrLF(from, true);
     236    case EndingLF:
     237        return convertToCROrLF(from, false);
     238    default:
     239        ASSERT_NOT_REACHED();
     240    }
     241
     242    ASSERT_NOT_REACHED();
     243    return from;
    194244}
    195245
Note: See TracChangeset for help on using the changeset viewer.