+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.
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
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>"
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>"
<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>
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)
log("after creation: " + stateName(req.readyState));
+ log("ResponseText: " + prettyPrintText(req.responseText));
+
if (async)
req.onreadystatechange = processStateChange;
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>
<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>
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)
log("after creation: " + stateName(req.readyState));
+ log("ResponseText: " + prettyPrintText(req.responseText));
+
if (async)
req.onreadystatechange = processStateChange;
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
+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.
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();
, m_async(true)
, m_job(0)
, m_state(Uninitialized)
+ , m_response("", 0)
, m_createdDocument(false)
, m_aborted(false)
{
// clear stuff from possible previous load
m_requestHeaders = DeprecatedString();
m_responseHeaders = String();
- m_response = DeprecatedString();
+ m_response = "";
m_createdDocument = false;
m_responseXML = 0;