Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Sep 2006 17:37:13 +0000 (17:37 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Sep 2006 17:37:13 +0000 (17:37 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=10753
        REGRESSION: The beginning of a CSS file is missing

        Test: http/tests/incremental/slow-utf8-css.pl

        * loader/Decoder.cpp:
        (WebCore::Decoder::checkForCSSCharset): Use the same buffering logic as used for HTML.
        (WebCore::Decoder::decode):
        * loader/Decoder.h: Added a return value and a movedDataToBuffer parameter to
        checkForCSSCharset().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16263 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/incremental/slow-utf8-css-expected.checksum [new file with mode: 0644]
LayoutTests/http/tests/incremental/slow-utf8-css-expected.png [new file with mode: 0644]
LayoutTests/http/tests/incremental/slow-utf8-css-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/incremental/slow-utf8-css.pl [new file with mode: 0755]
WebCore/ChangeLog
WebCore/loader/Decoder.cpp
WebCore/loader/Decoder.h

index 7d77776..5d9ea0b 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=10753
+        REGRESSION: The beginning of a CSS file is missing
+
+        * http/tests/incremental/slow-utf8-css-expected.checksum: Added.
+        * http/tests/incremental/slow-utf8-css-expected.png: Added.
+        * http/tests/incremental/slow-utf8-css-expected.txt: Added.
+        * http/tests/incremental/slow-utf8-css.pl: Added.
+
 2006-09-07  Rob Buis  <buis@kde.org>
 
         Reviewed by Maciej.
diff --git a/LayoutTests/http/tests/incremental/slow-utf8-css-expected.checksum b/LayoutTests/http/tests/incremental/slow-utf8-css-expected.checksum
new file mode 100644 (file)
index 0000000..0229bf4
--- /dev/null
@@ -0,0 +1 @@
+f539542b8e5ca8ed5877dc065488a7ba
\ No newline at end of file
diff --git a/LayoutTests/http/tests/incremental/slow-utf8-css-expected.png b/LayoutTests/http/tests/incremental/slow-utf8-css-expected.png
new file mode 100644 (file)
index 0000000..780dd68
Binary files /dev/null and b/LayoutTests/http/tests/incremental/slow-utf8-css-expected.png differ
diff --git a/LayoutTests/http/tests/incremental/slow-utf8-css-expected.txt b/LayoutTests/http/tests/incremental/slow-utf8-css-expected.txt
new file mode 100644 (file)
index 0000000..43e2ccf
--- /dev/null
@@ -0,0 +1,12 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x579
+      RenderBlock {PRE} at (0,0) size 784x45
+        RenderText {#text} at (0,0) size 472x30
+          text run at (0,0) width 472: "Test for bug 10753: The beginning of a CSS file is missing."
+          text run at (472,0) width 0: " "
+          text run at (0,15) width 0: " "
+        RenderText {#text} at (0,30) size 736x15
+          text run at (0,30) width 736: "You should see a bug description one line above (i.e., this line shouldn't be the only one)."
diff --git a/LayoutTests/http/tests/incremental/slow-utf8-css.pl b/LayoutTests/http/tests/incremental/slow-utf8-css.pl
new file mode 100755 (executable)
index 0000000..80ab584
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/perl -w
+
+# flush the buffers after each print
+select (STDOUT);
+$| = 1;
+
+print "Content-Type: text/css; charset=utf-8\n";
+print "Expires: Thu, 01 Dec 2003 16:00:00 GMT\n";
+print "Cache-Control: no-store, no-cache, must-revalidate\n";
+print "Pragma: no-cache\n";
+print "\n";
+
+print "\xef\xbb\xbfTest for bug 10753: The beginning of a CSS file is missing.\n\n";
+for ($count=1; $count<4000; $count++) { # dump some BOMs to bypass CFNetwork buffering
+    print "\xef\xbb\xbf";
+}
+print "You should see a bug description one line above (i.e., this line shouldn't be the only one).";
index f3db1c2..4cb8992 100644 (file)
@@ -1,3 +1,18 @@
+2006-09-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10753
+        REGRESSION: The beginning of a CSS file is missing
+
+        Test: http/tests/incremental/slow-utf8-css.pl
+
+        * loader/Decoder.cpp:
+        (WebCore::Decoder::checkForCSSCharset): Use the same buffering logic as used for HTML.
+        (WebCore::Decoder::decode):
+        * loader/Decoder.h: Added a return value and a movedDataToBuffer parameter to
+        checkForCSSCharset().
+
 2006-09-07  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Darin.
index 90d3404..59707c6 100644 (file)
@@ -379,17 +379,19 @@ void Decoder::checkForBOM(const char* data, size_t len)
         setEncoding(UTF8Encoding(), AutoDetectedEncoding);
 }
 
-void Decoder::checkForCSSCharset(const char* data, size_t len)
+bool Decoder::checkForCSSCharset(const char* data, size_t len, bool& movedDataToBuffer)
 {
     if (m_source != DefaultEncoding) {
         m_checkedForCSSCharset = true;
-        return;
+        return true;
     }
 
     size_t oldSize = m_buffer.size();
     m_buffer.resize(oldSize + len);
     memcpy(m_buffer.data() + oldSize, data, len);
 
+    movedDataToBuffer = true;
+
     if (m_buffer.size() > 8) { // strlen("@charset") == 8
         const char* dataStart = m_buffer.data();
         const char* dataEnd = dataStart + m_buffer.size();
@@ -400,7 +402,7 @@ void Decoder::checkForCSSCharset(const char* data, size_t len)
             dataStart += 8;
             const char* pos = dataStart;
             if (!skipWhitespace(pos, dataEnd))
-                return;
+                return false;
 
             if (*pos == '"' || *pos == '\'') {
                 char quotationMark = *pos;
@@ -410,20 +412,22 @@ void Decoder::checkForCSSCharset(const char* data, size_t len)
                 while (pos < dataEnd && *pos != quotationMark)
                     ++pos;
                 if (pos == dataEnd)
-                    return;
+                    return false;
 
                 DeprecatedCString encodingName(dataStart, pos - dataStart + 1);
                 
                 ++pos;
                 if (!skipWhitespace(pos, dataEnd))
-                    return;
+                    return false;
 
                 if (*pos == ';')
                     setEncoding(TextEncoding(encodingName), EncodingFromCSSCharset);
             }
         }
         m_checkedForCSSCharset = true;
+        return true;
     }
+    return false;
 }
 
 // Other browsers allow comments in the head section, so we need to also.
@@ -625,17 +629,15 @@ String Decoder::decode(const char* data, size_t len)
     if (!m_checkedForBOM)
         checkForBOM(data, len);
 
-    if (m_contentType == CSS && !m_checkedForCSSCharset) {
-        checkForCSSCharset(data, len);
-        return "";
-    }
-
     bool movedDataToBuffer = false;
 
-    if ((m_contentType == HTML || m_contentType == XML) && !m_checkedForHeadCharset) { // HTML and XML
+    if (m_contentType == CSS && !m_checkedForCSSCharset)
+        if (!checkForCSSCharset(data, len, movedDataToBuffer))
+            return "";
+
+    if ((m_contentType == HTML || m_contentType == XML) && !m_checkedForHeadCharset) // HTML and XML
         if (!checkForHeadCharset(data, len, movedDataToBuffer))
             return "";
-    }
 
     // Do the auto-detect if our default encoding is one of the Japanese ones.
     // FIXME: It seems wrong to change our encoding downstream after we have already done some decoding.
index 4741154..59d6244 100644 (file)
@@ -59,7 +59,7 @@ private:
     static const TextEncoding& defaultEncoding(ContentType, const TextEncoding& defaultEncoding);
 
     void checkForBOM(const char*, size_t);
-    void checkForCSSCharset(const char*, size_t);
+    bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer);
     bool checkForHeadCharset(const char*, size_t, bool& movedDataToBuffer);
     void detectJapaneseEncoding(const char*, size_t);