Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jan 2007 16:33:35 +0000 (16:33 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jan 2007 16:33:35 +0000 (16:33 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=12165
        REGRESSION: text encoding problem at jn.sapo.pt

        Test: fast/encoding/script-in-head.html

        * loader/TextResourceDecoder.cpp:
        (WebCore::TextResourceDecoder::checkForHeadCharset):
        Ignore tags within <script> elements in head, just like we do for <title>.

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

LayoutTests/ChangeLog
LayoutTests/fast/encoding/script-in-head-expected.txt [new file with mode: 0644]
LayoutTests/fast/encoding/script-in-head.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/loader/TextResourceDecoder.cpp

index e66cfb5..709dafd 100644 (file)
@@ -1,3 +1,13 @@
+2007-01-13  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        Test for http://bugs.webkit.org/show_bug.cgi?id=12165
+        REGRESSION: text encoding problem at jn.sapo.pt
+
+        * fast/encoding/script-in-head-expected.txt: Added.
+        * fast/encoding/script-in-head.html: Added.
+
 2007-01-13  Eric Seidel  <eric@webkit.org>
 
         Reviewed by hyatt.
diff --git a/LayoutTests/fast/encoding/script-in-head-expected.txt b/LayoutTests/fast/encoding/script-in-head-expected.txt
new file mode 100644 (file)
index 0000000..4cccf83
--- /dev/null
@@ -0,0 +1,6 @@
+Test for bug 12165: text encoding problem at jn.sapo.pt
+
+Should see a success message below.
+
+SUССЕSS
+
diff --git a/LayoutTests/fast/encoding/script-in-head.html b/LayoutTests/fast/encoding/script-in-head.html
new file mode 100644 (file)
index 0000000..dfb8076
--- /dev/null
@@ -0,0 +1,30 @@
+<!-- temp --><script language="JavaScript" type="text/JavaScript">
+document.write ('<SCR' + 'IPT>' +
+    'if (window.layoutTestController) {' +
+        'layoutTestController.dumpAsText();' +
+        'layoutTestController.waitUntilDone();' +
+    '}' +
+
+    'setTimeout(function () {' +
+        <!-- The letters CCE below are Cyrillic, so we do test that the encoding is correct. -->
+        <!-- We also take an opportunity to test that this weirdly located script actually executes. -->
+        'document.getElementById("result").innerHTML="SUóóåSS";' +
+        'if (window.layoutTestController)' +
+            'layoutTestController.notifyDone();' +
+    '}, 0);' +
+'</SCR' + 'IPT>'); </script>
+<!-- /temp --><!--HEADER-->
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
+</head>
+<body>
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=12165">bug 12165</a>:
+text encoding problem at jn.sapo.pt</p>
+<p>Should see a success message below.</p>
+<div id="result"></div>
+</body>
+</html>
index 10eff2b..7fe4a74 100644 (file)
@@ -1,3 +1,16 @@
+2007-01-13  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=12165
+        REGRESSION: text encoding problem at jn.sapo.pt
+
+        Test: fast/encoding/script-in-head.html
+
+        * loader/TextResourceDecoder.cpp:
+        (WebCore::TextResourceDecoder::checkForHeadCharset):
+        Ignore tags within <script> elements in head, just like we do for <title>.
+
 2007-01-13  Lars Knoll <lars@trolltech.com>
 
         Reviewed by Maciej
index 9799f99..6af4fbf 100644 (file)
@@ -483,10 +483,12 @@ bool TextResourceDecoder::checkForHeadCharset(const char* data, size_t len, bool
     // matches behavior in other browsers; more details in
     // <http://bugs.webkit.org/show_bug.cgi?id=3590>.
     
-    // Additionally, we ignore things that looks like tags in <title>; see
-    // <http://bugs.webkit.org/show_bug.cgi?id=4560>.
+    // Additionally, we ignore things that looks like tags in <title> and <script>; see
+    // <http://bugs.webkit.org/show_bug.cgi?id=4560> and
+    // <http://bugs.webkit.org/show_bug.cgi?id=12165>.
     
     bool withinTitle = false;
+    bool withinScript = false;
 
     const char* ptr = m_buffer.data();
     const char* pEnd = ptr + m_buffer.size();
@@ -548,6 +550,8 @@ bool TextResourceDecoder::checkForHeadCharset(const char* data, size_t len, bool
             
             if (tag == titleTag)
                 withinTitle = !end;
+            else if (tag == scriptTag)
+                withinScript = !end;
             
             if (!end && tag == metaTag) {
                 const char* end = ptr;
@@ -593,7 +597,7 @@ bool TextResourceDecoder::checkForHeadCharset(const char* data, size_t len, bool
             } else if (tag != scriptTag && tag != noscriptTag && tag != styleTag &&
                        tag != linkTag && tag != metaTag && tag != objectTag &&
                        tag != titleTag && tag != baseTag && 
-                       (end || tag != htmlTag) && !withinTitle &&
+                       (end || tag != htmlTag) && !withinTitle && !withinScript &&
                        (tag != headTag) && isalpha(tmp[0])) {
                 m_checkedForHeadCharset = true;
                 return true;