Closed Bug 484396 Opened 15 years ago Closed 14 years ago

XMLHttpRequest.open throws exception on empty string url parameter

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: lists.bugzilla, Assigned: ttaubert)

References

()

Details

(Keywords: testcase, Whiteboard: [good first bug])

Attachments

(1 file, 5 obsolete files)

User-Agent:       Opera/9.61 (Windows NT 5.1; U; en) Presto/2.1.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7

The following code alerts the fail message. Latest version of Opera and Chrome alert the success message, and will re-fetch the document if xhr.send() is called. According to the latest XHR draft spec, the empty URL value should be allowed and resolved against the document's base URI.

<!DOCTYPE html>
<html><body><script type="text/javascript">
    var xhr = new XMLHttpRequest();
    try {
        xhr.open( 'GET', '' );
        alert( 'open succeeded' );
    } catch (e) {
        alert( 'open failed: ' + e );
    }
</script></body></html>

Reproducible: Always

Steps to Reproduce:
1. Save the code snippet provided into a HTML file.
2. Load the HTML file in Firefox.
3. Check the message in the alert dialog box.
Actual Results:  
The alert dialog box says:
open failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest open]" nsresult: "0x8007057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://example.com/xhr.html :: <TOP_LEVEL> :: line 7" data: no]

Expected Results:  
The alert dialog box should say:
open succeeded
Attached file testcase (obsolete) —
I can reproduce with trunk.
Component: General → DOM
Keywords: testcase
OS: Windows XP → All
Product: Firefox → Core
QA Contact: general → general
Hardware: x86 → All
Version: unspecified → Trunk
Confirmed.
Status: UNCONFIRMED → NEW
Component: DOM → DOM: Mozilla Extensions
Ever confirmed: true
This probably is as easy as removing

   NS_ENSURE_ARG(!url.IsEmpty());

from nsXMLHttpRequest::OpenRequest.
Whiteboard: [good first bug]
Attachment #499494 - Flags: review?(Olli.Pettay)
Attachment #499494 - Attachment is obsolete: true
Attachment #499764 - Flags: review?(Olli.Pettay)
Attachment #499494 - Flags: review?(Olli.Pettay)
Could you please add some test which checks that XHR with empty url actually 
works.
I mean some test which checks that after xhr.send() when load event has been
dispatched, .responseText and/or .responseXML contain some valid value.
My first version already contained all the tests and I removed them because I tought they were too much... :)
Attachment #499764 - Attachment is obsolete: true
Attachment #499809 - Flags: review?(Olli.Pettay)
Attachment #499764 - Flags: review?(Olli.Pettay)
Comment on attachment 499809 [details] [diff] [review]
v3, testing xhr.open(), xhr.send() and xhr.responseText


>diff --git a/content/base/test/test_bug484396.html b/content/base/test/test_bug484396.html
>new file mode 100644
>--- /dev/null
>+++ b/content/base/test/test_bug484396.html
>@@ -0,0 +1,49 @@
>+<!DOCTYPE HTML>
>+<html>
>+<!--
>+https://bugzilla.mozilla.org/show_bug.cgi?id=484396
>+-->
>+<head>
>+  <title>Test for Bug 484396</title>
>+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
>+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
>+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
>+</head>
>+<body>
>+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484396">Mozilla Bug 484396</a>
>+<p id="display"></p>
>+<div id="content" style="display: none">
>+  
>+</div>
>+<pre id="test">
>+<script type="application/javascript;version=1.8">
>+SimpleTest.waitForExplicitFinish();
>+
>+let msg = 'xhr.open() succeeds with empty url';
>+let xhr = new XMLHttpRequest();
Please use 'var' so that the testcase could run also in browsers which don't support 'let'.
Attachment #499809 - Flags: review?(Olli.Pettay) → review+
Attached patch v4, replaced let with var (obsolete) — Splinter Review
I knew the first patch would not be that 'easy' :) Thanks for your review.
Attachment #499809 - Attachment is obsolete: true
Attachment #499810 - Flags: review+
Attachment #499810 - Flags: approval2.0?
Comment on attachment 499810 [details] [diff] [review]
v4, replaced let with var

Thanks for your patch, Tim! I'd like to note that, when carrying forward review, it's preferred not to set r+ yourself, though.
Attachment #499810 - Flags: review+
Assignee: nobody → tim.taubert
Attachment #499810 - Flags: approval2.0?
Pushed patch v5 to try today. Passed.
Attachment #368633 - Attachment is obsolete: true
Attachment #499810 - Attachment is obsolete: true
Attachment #501387 - Flags: approval2.0?
Comment on attachment 501387 [details] [diff] [review]
patch v5 (updated to work with trunk again)

a=me

Tim, do you need this checked in, or can you land it?
Attachment #501387 - Flags: approval2.0? → approval2.0+
http://hg.mozilla.org/mozilla-central/rev/6352187435e5
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: