Reviewed by Anders.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jun 2007 19:01:30 +0000 (19:01 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jun 2007 19:01:30 +0000 (19:01 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=13905
        REGRESSION: A Chinese dictionary widget has a problem with XMLHttpRequest response encoding

        Tiger WebKit accidentally looked at HTML Http-Equiv META to determine the response encoding
        (regardless of the actual response MIME type). This was corrected a while ago to match other
        browsers and the draft XHR spec.

        Now restoring this functionality for "text/html", with spec editor's blessing.

        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::responseMIMEType):
        (WebCore::XMLHttpRequest::responseIsXML):
        (WebCore::XMLHttpRequest::didReceiveData):
        * xml/xmlhttprequest.h:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/resources/1251.html [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/response-encoding-expected.txt
LayoutTests/http/tests/xmlhttprequest/response-encoding.html
WebCore/ChangeLog
WebCore/xml/xmlhttprequest.cpp
WebCore/xml/xmlhttprequest.h

index e8d572b29b2011e7ebe9429c84d9b76e90426d67..487d99f5607a73742d15a9b586e1ef2fa402c968 100644 (file)
@@ -1,3 +1,14 @@
+2007-06-21  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Anders.
+
+        http://bugs.webkit.org/show_bug.cgi?id=13905
+        REGRESSION: A Chinese dictionary widget has a problem with XMLHttpRequest response encoding
+
+        * http/tests/xmlhttprequest/resources/1251.html: Added.
+        * http/tests/xmlhttprequest/response-encoding-expected.txt:
+        * http/tests/xmlhttprequest/response-encoding.html:
+
 2007-06-21  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Anders.
diff --git a/LayoutTests/http/tests/xmlhttprequest/resources/1251.html b/LayoutTests/http/tests/xmlhttprequest/resources/1251.html
new file mode 100644 (file)
index 0000000..645ff2a
--- /dev/null
@@ -0,0 +1,6 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=windows-1251">
+</head>
+<body>Ïðîâåðêà</body>
+</html>
index c057447ca958cec4b002cda2491dfcb755217613..60e1f8f7c980fa987d6282f038a43fed494ab32a 100644 (file)
@@ -18,3 +18,4 @@ Async: XML, windows-1251 specified in XML declaration: Проверка. respons
 Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in HTTP headers: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
 Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
 Async: XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
+Async: HTML, charset determined by a META: Проверка
index cdd808c2e9bf35299bd9f89f7bceaaf989f3308a..dce51ba01eb57d37ddd8dca01c51b36b879a90ba 100644 (file)
              getWithOverride('resources/reply3.xml', 'text/xml; charset=windows-1251', true);
            } else if (asyncStep == 8) {
              asyncStep = 9;
-             log("Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
+             log("Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: " + 
+                 (req.responseXML ? req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue  : "<No responseXML>") + ". responseText: " + req.responseText);
              get('resources/reply5.txt', true);
            } else if (asyncStep == 9) {
+             asyncStep = 10;
              log("Async: XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): " + req.responseText);
+             get('resources/1251.html', true);
+           } else if (asyncStep == 10) {
+             log("Async: HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
            }
         } else {
            log("Error loading URL: status " + req.status);
index 712888b122663feb45cab56a66ae788c5edc0923..df90bf378457e754c5331e5a5e4f7988ef07df2d 100644 (file)
@@ -1,3 +1,22 @@
+2007-06-21  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Anders.
+
+        http://bugs.webkit.org/show_bug.cgi?id=13905
+        REGRESSION: A Chinese dictionary widget has a problem with XMLHttpRequest response encoding
+
+        Tiger WebKit accidentally looked at HTML Http-Equiv META to determine the response encoding
+        (regardless of the actual response MIME type). This was corrected a while ago to match other 
+        browsers and the draft XHR spec.
+
+        Now restoring this functionality for "text/html", with spec editor's blessing.
+
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::responseMIMEType):
+        (WebCore::XMLHttpRequest::responseIsXML):
+        (WebCore::XMLHttpRequest::didReceiveData):
+        * xml/xmlhttprequest.h:
+
 2007-06-21  Andrew Wellington  <proton@wiretapped.net>
 
         Mac build fix.
index 88303277a40ad79ee2de9b69437345f1c27f7e65..4d715d2232f0dd22867ef358b9ed25ea82efdfd6 100644 (file)
@@ -579,14 +579,20 @@ String XMLHttpRequest::getResponseHeader(const String& name) const
     return m_response.httpHeaderField(name);
 }
 
-bool XMLHttpRequest::responseIsXML() const
+String XMLHttpRequest::responseMIMEType() const
 {
     String mimeType = getMIMEType(m_mimeTypeOverride);
     if (mimeType.isEmpty())
         mimeType = getMIMEType(getResponseHeader("Content-Type"));
     if (mimeType.isEmpty())
         mimeType = "text/xml";
-    return DOMImplementation::isXMLMIMEType(mimeType);
+    
+    return mimeType;
+}
+
+bool XMLHttpRequest::responseIsXML() const
+{
+    return DOMImplementation::isXMLMIMEType(responseMIMEType());
 }
 
 int XMLHttpRequest::getStatus(ExceptionCode& ec) const
@@ -697,9 +703,11 @@ void XMLHttpRequest::didReceiveData(SubresourceLoader*, const char* data, int le
     if (!m_decoder) {
         if (!m_encoding.isEmpty())
             m_decoder = new TextResourceDecoder("text/plain", m_encoding);
+        // allow TextResourceDecoder to look inside the m_response if it's XML or HTML
         else if (responseIsXML())
-            // allow TextResourceDecoder to look inside the m_response if it's XML
             m_decoder = new TextResourceDecoder("application/xml");
+        else if (responseMIMEType() == "text/html")
+            m_decoder = new TextResourceDecoder("text/html");
         else
             m_decoder = new TextResourceDecoder("text/plain", "UTF-8");
     }
index ea37b01ec225d0abee3bcf7a6b8aa743943523fd..19542bb101b78f8ed515e1acf5b70eb334b5748e 100644 (file)
@@ -113,6 +113,7 @@ private:
 
     void processSyncLoadResults(const Vector<char>& data, const ResourceResponse&);
 
+    String responseMIMEType() const;
     bool responseIsXML() const;
 
     String getRequestHeader(const String& name) const;