Closed Bug 128541 Opened 23 years ago Closed 23 years ago

XMLHttpRequest.send(null) fails

Categories

(Core :: XML, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.0

People

(Reporter: hjtoi-bugzilla, Assigned: hjtoi-bugzilla)

Details

(Keywords: regression)

Attachments

(3 files, 1 obsolete file)

Michael Gannon reported this in n.p.m.xml. Need a testcase, which should be easy to using this info here. I think Michael's patch will not fix it, but I have a hunch where the problem lies... Michael wrote: I am trying to use the XMLHttpRequest object to create a WebDAV client and have come across what I believe to be a bug related to the above bug. When the send() method called from a JS file with null as the parameter I get the following error [Exception... "Component returned failure code: 0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA) [nsIXMLHttpRequest.send]" nsresult: "0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA)" The following excerpt of code is where the exception is being thrown: var req = new XMLHttpRequest(); req.open("PROPFIND", href, false); req.setRequestHeader("Depth", "0"); req.send(null); I believe that this is because the method - nsXMLHttpRequest::Send(nsIVariant *aBody) - expects a nsIVariant parameter, but it assumes that it is either a DOM object or a string and not of type 'NULL'. I've created a patch below that should fix this (I think...): *** nsXMLHttpRequest.cpp.bak Thu Feb 7 00:19:04 2002 --- nsXMLHttpRequest.cpp Tue Feb 26 18:56:57 2002 *************** *** 1020,1025 **** --- 1020,1028 ---- } } } + } else if (dataType == nsIDataType::VTYPE_VOID || dataType == nsIDataType::VTYPE_EMPTY) { + // do nothing... + // param was null... } else { // try variant string rv = aBody->GetAsWString(getter_Copies(serial)); Basically, this just adds a check to see if the datatype of the nsIVariant parameter is of type null/void and does nothing if it is... Else it assumes that it is a string.
This testcase, tries to send the OPTIONS command to a HTTP server and currently fails with an exception.
I've been using 0.9.9 for a few weeks now, with the above patch applied and it has been working fine. What might be better though, is if it explicity checked for a 'string' argument, instead of defaulting to that. And if 'null' is passed in, it will implicitly ignore it.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Target Milestone: --- → mozilla1.0
Does the patch, also fix xmlhttp.send() - which is what MS recommend for not passing arguments? This currently generates a Error: uncaught exception: [Exception... "Not enough arguments [nsIXMLHttpRequest.send]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" If not can we make it so please? It's needded to match IE's behaviour and it's unnatural in ECMAScript objects to be forced into passing null - passing an empty string is also definately wrong IMO for HEAD etc. requests, there's no information passed with such a request, which is conceptually distinct from an empty string.
Johnny, would it be possible to make XMLHttpRequest.send() accept 0 or 1 arguments?
Status: NEW → ASSIGNED
ARGH! This is a major regression. When I added support for nsIVariant I did not realize it would mean calls from JS would ALWAYS come with aBody != 0 (i.e. of type empty or something). So as the situation is now, all operations that pass null that are not GET are likely to fail. I am pretty sure any serious user of XMLHttpRequest is going to hit this, for example DIG group etc. I also think Michael's suggestion to explicitly list string types to convert to is better than what there is now. Will attach another patch.
Severity: normal → major
Keywords: nsbeta1+, regression
Whiteboard: [fixinhand]
Attached patch Better fixSplinter Review
I changed the outermost if-clause to a switch statement. VOID and EMPTY will reduce to same as no parameter (this bug originally). While testing, I realized IE will throw errors for arrays (invalid parameter), and will happily accept and serialize numbers. This will make us match IE more closely. Reviews, John & Johnny?
Attachment #79045 - Attachment is obsolete: true
Changing QA Contact
QA Contact: petersen → rakeshmishra
Comment on attachment 79048 [details] [diff] [review] Better fix sr=jst
Attachment #79048 - Flags: superreview+
Comment on attachment 79048 [details] [diff] [review] Better fix r=harishd
Attachment #79048 - Flags: review+
Checked in to trunk, sending for drivers & ADT approval.
Keywords: adt1.0.0
Whiteboard: [fixinhand] → [fixed on trunk]
Comment on attachment 79048 [details] [diff] [review] Better fix a=rjesup@wgate.com for branch checkin
Attachment #79048 - Flags: approval+
Rakesh, can you verify the fix on the trunk and comment in the bug when done.
Verified on the build 2002-04-16-06-trunk on Win 2000 machine.
Verified on the build 2002-04-16-06-trunk(Win 2000) with the modified test case, Testcase_bug128541_new.html
adt1.0.0+ on behalf of the adt. Please check into the branch today and add fixed1.0.0 to the keyword field.
Keywords: adt1.0.0adt1.0.0+
Checked in on branch as well.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Keywords: adt1.0.0+fixed1.0.0
Resolution: --- → FIXED
Whiteboard: [fixed on trunk]
Rakesh had verified this on trunk earlier, marking as such.
Status: RESOLVED → VERIFIED
Verified on the branch build 2002-04-19-08-1.0.0 on Win 2000 machine. Checked with the above attachment "Modified test case for Bug # 128541 ". Adding "verified 1.0.0" to keywords.
Keywords: verified1.0.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: