Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2006 05:05:17 +0000 (05:05 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2006 05:05:17 +0000 (05:05 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
        XMLHttpRequest.responseText is null if HTTP response is empty

        Extended existing tests:
        - http/tests/xmlhttrequest/zero-length-response.html
        - http/tests/xmlhttrequest/zero-length-response-sync.html

        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::XMLHttpRequest): Initialize responseText to an empty string.
        (WebCore::XMLHttpRequest::open): Reset responseText to an empty string.
        * bindings/js/JSXMLHttpRequest.cpp:
        (KJS::JSXMLHttpRequest::getValueProperty): Return null rather than undefined
        for nil responseXML.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types-expected.txt
LayoutTests/http/tests/xmlhttprequest/zero-length-response-expected.txt
LayoutTests/http/tests/xmlhttprequest/zero-length-response-sync-expected.txt
LayoutTests/http/tests/xmlhttprequest/zero-length-response-sync.html
LayoutTests/http/tests/xmlhttprequest/zero-length-response.html
WebCore/ChangeLog
WebCore/bindings/js/JSXMLHttpRequest.cpp
WebCore/xml/xmlhttprequest.cpp

index 202a42d131fc1cd84886a477e2d3c0380376c8e9..f97802c837cb5cca82a824a9b6717854fe1630e4 100644 (file)
@@ -1,3 +1,24 @@
+2006-09-04  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        Tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
+        XMLHttpRequest.responseText is null if HTTP response is empty
+
+        The results are not fully correct yet:
+        - accessing properties that are now undefined should cause an exception;
+        - on error, responseXML should be null, rather than contain an HTML document describing 
+        the error.
+
+        * http/tests/xmlhttprequest/supported-xml-content-types-expected.txt: Updated for responseXML
+        now returning null for nil documents.
+
+        * http/tests/xmlhttprequest/zero-length-response-expected.txt:
+        * http/tests/xmlhttprequest/zero-length-response-sync-expected.txt:
+        * http/tests/xmlhttprequest/zero-length-response-sync.html:
+        * http/tests/xmlhttprequest/zero-length-response.html:
+        Extended to cover more properties.
+
 2006-09-04  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Darin.
index 482ce91a53b4bcc321ee969e84391d2023ba4cca..55b8a946c65c4cbb5c695fdd617d14fad98b091e 100644 (file)
@@ -40,42 +40,42 @@ PASS -- testing: foo&bar/baz+xml -- responseXML: [object Document]
 
 PASS -- testing: foo*bar/baz+xml -- responseXML: [object Document]
 
-PASS -- testing: text/html -- responseXML: undefined
+PASS -- testing: text/html -- responseXML: null
 
-PASS -- testing: image/png -- responseXML: undefined
+PASS -- testing: image/png -- responseXML: null
 
-PASS -- testing: invalid -- responseXML: undefined
+PASS -- testing: invalid -- responseXML: null
 
 FAIL (got document -- response type: foo bar/baz+xml) -- testing: foo bar/baz+xml -- responseXML: [object Document]
 
-PASS -- testing: foo[bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo[bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo]bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo]bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo(bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo(bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo)bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo)bar/baz+xml -- responseXML: null
 
 PASS -- testing: foo
 
-PASS -- testing: foo>bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo>bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo@bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo@bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo,bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo,bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo;bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo;bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo:bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo:bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo\bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo\bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo"bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo"bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo/bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo/bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo?bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo?bar/baz+xml -- responseXML: null
 
-PASS -- testing: foo=bar/baz+xml -- responseXML: undefined
+PASS -- testing: foo=bar/baz+xml -- responseXML: null
 
 
index cc3728675286c8c6ef6eb219a5da823dce1782f5..3675012ae95cb70b7c50075195c5d1899ce933d8 100644 (file)
@@ -1,10 +1,27 @@
 Test for bug 5924 - zero-length responses to XMLHTTPRequest mishandled.
 
 after creation: Uninitialized
+ResponseText: ""
 after setting onreadystatechange: Uninitialized
 onreadystatechange: Loading
+  Status: undefined
+  StatusText: undefined
+  ResponseText: ""
+  ResponseXML: null
+  ResponseXML serialized: n/a
 after open(): Loading
+after overrideMimeType(): Loading
 after send(): Loading
-onreadystatechange: Loaded. Status: 200
-onreadystatechange: Completed. Status: 200
+onreadystatechange: Loaded
+  Status: 200
+  StatusText: "OK"
+  ResponseText: ""
+  ResponseXML: null
+  ResponseXML serialized: n/a
+onreadystatechange: Completed
+  Status: 200
+  StatusText: "OK"
+  ResponseText: ""
+  ResponseXML: [object Document]
+  ResponseXML serialized: "<html><body><parsererror style="white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 1 at column 1: Extra content at the end of the document </div><h3>Below is a rendering of the page up to the first error.</h3></parsererror></body></html>"
 
index 8145efc6dac25d6fa09143dfd92f9c485c2ae2ae..766a01be384027387c97d74eab163ff7ead56e0c 100644 (file)
@@ -1,8 +1,14 @@
 Test for bug 5924 - zero-length responses to XMLHTTPRequest mishandled.
 
 after creation: Uninitialized
+ResponseText: ""
 after setting onreadystatechange: Uninitialized
 after open(): Loading
+after overrideMimeType(): Loading
 after send(): Completed
-Status: 200
+  Status: 200
+  StatusText: "OK"
+  ResponseText: ""
+  ResponseXML: [object Document]
+  ResponseXML serialized: "<html><body><parsererror style="white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 1 at column 1: Extra content at the end of the document </div><h3>Below is a rendering of the page up to the first error.</h3></parsererror></body></html>"
 
index 8daa90e05e3471f343571369e25189746024d880..fc743050b73eba3364d602dffce4134f57e47c3a 100644 (file)
@@ -1,6 +1,7 @@
 <html>
 <head>
 <title>Test XmlHttpRequest zero-length response handling (sync)</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8">
 <body>
 <p>Test for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=5924">bug 5924</a>
 - zero-length responses to XMLHTTPRequest mishandled.</p>
@@ -9,7 +10,7 @@
     if (window.layoutTestController)
         layoutTestController.dumpAsText();
 
-    var console_messages = document.createElement("ol");
+    var console_messages = document.createElement("ul");
     document.body.appendChild(console_messages);
     
     function log(message)
@@ -33,6 +34,8 @@
         
         log("after creation: " + stateName(req.readyState));
         
+        log("ResponseText: " + prettyPrintText(req.responseText));
+
         if (async)
             req.onreadystatechange = processStateChange;
         
@@ -40,6 +43,8 @@
 
         req.open('GET', url, async);
         log("after open(): " + stateName(req.readyState));
+        req.overrideMimeType('text/xml');
+        log("after overrideMimeType(): " + stateName(req.readyState));
         req.send(null);
         log("after send(): " + stateName(req.readyState));
 
         return "???";
     }
     
-    function processStateChange(){
-      if (req.readyState < 2)
-        log("onreadystatechange: " + stateName(req.readyState));
-      else
-        log("onreadystatechange: " + stateName(req.readyState) + ". Status: " + req.status);
+    function prettyPrintText(text) {
+        if (text == null)
+            return text;
+        else
+            return '"' + text + '"';
+    }
+
+    function dumpResponse() {
+       try { log ("  Status: " + req.status); } catch (ex) { log("  Exception getting status: " + ex.message); }
+       try { log ("  StatusText: " + prettyPrintText(req.statusText)); } catch (ex) { log("  Exception getting StatusText: " + ex.message); }
+       try { log ("  ResponseText: " + prettyPrintText(req.responseText)); } catch (ex) { log("  Exception getting ResponseText: " + ex.message); }
+       try { log ("  ResponseXML: " + req.responseXML); } catch (ex) { log("  Exception getting ResponseXML: " + ex.message); }
+       try { log ("  ResponseXML serialized: " + (req.responseXML ? prettyPrintText(window.XMLSerializer ? (new XMLSerializer()).serializeToString(req.responseXML) : req.responseXML.xml) : "n/a")); } catch (ex) { log("  Exception serializing ResponseXML: " + ex.message); }
+    }
+
+    function processStateChange() {
+      log("onreadystatechange: " + stateName(req.readyState));
+      dumpResponse();
     }
     
-    // start async steps
     get('resources/zero-length.txt', false);
-    log("Status: " + req.status);
+    dumpResponse();
 </script>
 </body>
 </html>
index bb5d4da2dd623df10c6f9c9aa977bf3455e7e11e..6316773a0d3c5b20822217209d464fd02f353da3 100644 (file)
@@ -1,6 +1,7 @@
 <html>
 <head>
 <title>Test XmlHttpRequest zero-length response handling (async)</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8">
 <body>
 <p>Test for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=5924">bug 5924</a>
 - zero-length responses to XMLHTTPRequest mishandled.</p>
@@ -9,7 +10,7 @@
     if (window.layoutTestController)
         layoutTestController.dumpAsText();
 
-    var console_messages = document.createElement("ol");
+    var console_messages = document.createElement("ul");
     document.body.appendChild(console_messages);
     
     function log(message)
@@ -33,6 +34,8 @@
         
         log("after creation: " + stateName(req.readyState));
         
+        log("ResponseText: " + prettyPrintText(req.responseText));
+
         if (async)
             req.onreadystatechange = processStateChange;
         
@@ -40,6 +43,8 @@
 
         req.open('GET', url, async);
         log("after open(): " + stateName(req.readyState));
+        req.overrideMimeType('text/xml');
+        log("after overrideMimeType(): " + stateName(req.readyState));
         req.send(null);
         log("after send(): " + stateName(req.readyState));
 
         return "???";
     }
     
-    function processStateChange(){
-      if (req.readyState < 2)
-        log("onreadystatechange: " + stateName(req.readyState));
-      else
-        log("onreadystatechange: " + stateName(req.readyState) + ". Status: " + req.status);
+    function prettyPrintText(text) {
+        if (text == null)
+            return text;
+        return '"' + text + '"';
+    }
+    
+    function dumpResponse() {
+
+       try { log ("  Status: " + req.status); } catch (ex) { log("  Exception getting status: " + ex.message); }
+       try { log ("  StatusText: " + prettyPrintText(req.statusText)); } catch (ex) { log("  Exception getting StatusText: " + ex.message); }
+       try { log ("  ResponseText: " + prettyPrintText(req.responseText)); } catch (ex) { log("  Exception getting ResponseText: " + ex.message); }
+       try { log ("  ResponseXML: " + req.responseXML); } catch (ex) { log("  Exception getting ResponseXML: " + ex.message); }
+       try { log ("  ResponseXML serialized: " + (req.responseXML ? prettyPrintText(window.XMLSerializer ? (new XMLSerializer()).serializeToString(req.responseXML) : req.responseXML.xml) : "n/a")); } catch (ex) { log("  Exception serializing ResponseXML: " + ex.message); }
+    }
+
+    function processStateChange() {
+       log("onreadystatechange: " + stateName(req.readyState));
+       dumpResponse();
     }
     
     // start async steps
index 744b318129df55aa97411df272851b582762b8cd..bdc8568a939bfe42d37cb192cbea08acd219b3c5 100644 (file)
@@ -1,3 +1,21 @@
+2006-09-04  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
+        XMLHttpRequest.responseText is null if HTTP response is empty
+
+        Extended existing tests:
+        - http/tests/xmlhttrequest/zero-length-response.html
+        - http/tests/xmlhttrequest/zero-length-response-sync.html
+
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::XMLHttpRequest): Initialize responseText to an empty string.
+        (WebCore::XMLHttpRequest::open): Reset responseText to an empty string.
+        * bindings/js/JSXMLHttpRequest.cpp:
+        (KJS::JSXMLHttpRequest::getValueProperty): Return null rather than undefined
+        for nil responseXML.
+
 2006-09-04  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Darin.
index c71023aab7cd0560ebe1b669ff97f53bac70b496..3a75c13c8dfa67bcce6657c17241b34b853b0656 100644 (file)
@@ -96,7 +96,7 @@ JSValue* JSXMLHttpRequest::getValueProperty(ExecState *exec, int token) const
   case ResponseXML:
     if (Document* responseXML = m_impl->getResponseXML())
       return toJS(exec, responseXML);
-    return jsUndefined();
+    return jsNull();
   case Status: {
     int status = m_impl->getStatus();
     return status > 0 ? jsNumber(status) : jsUndefined();
index 5cab0dd691df13e47fd5fa670c1234081265e751..a50d131d7db0dcc73b07c83c066412fa5a868143 100644 (file)
@@ -189,6 +189,7 @@ XMLHttpRequest::XMLHttpRequest(Document *d)
     , m_async(true)
     , m_job(0)
     , m_state(Uninitialized)
+    , m_response("", 0)
     , m_createdDocument(false)
     , m_aborted(false)
 {
@@ -244,7 +245,7 @@ void XMLHttpRequest::open(const String& method, const KURL& url, bool async, con
     // clear stuff from possible previous load
     m_requestHeaders = DeprecatedString();
     m_responseHeaders = String();
-    m_response = DeprecatedString();
+    m_response = "";
     m_createdDocument = false;
     m_responseXML = 0;