Closed Bug 1579331 Opened 5 years ago Closed 5 years ago

URL constructor fails when input is a data URL without a comma

Categories

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

71 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla71
Tracking Status
firefox71 --- fixed

People

(Reporter: saschanaz, Assigned: valentin)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

new URL("data:foo");

All Chrome, Edge, and Safari successfully can create a URL instance but Firefox fails to do so.

I suspect this should be a duplicate but couldn't find any existing relevant bug.

Anne, Baku, wdyt?

Flags: needinfo?(annevk)
Flags: needinfo?(amarchesini)

In URL API, we call NS_NewURI() and this returns an error when parsing data:foo.
See: https://searchfox.org/mozilla-central/rev/2c0a60b5b065ae0fdfcfae168141e82b834fb2d4/dom/url/URL.cpp#68

Because the URL doesn't contain a comma, we return NS_ERROR_MALFORMED_URI:
https://searchfox.org/mozilla-central/rev/2c0a60b5b065ae0fdfcfae168141e82b834fb2d4/netwerk/protocol/data/nsDataHandler.cpp#159

Valentin is on PTO. Dragana, who can take a look whether this is a bug in our data: URL parser?

Flags: needinfo?(amarchesini) → needinfo?(dd.mozilla)

Doesn't seem like the comma is optional according to https://tools.ietf.org/html/rfc2397, which says it's

data:[<mediatype>][;base64],<data>

and wikipedia says

The comma is required in a data URI, even when the data part has zero length.

Summary: URL constructor fails when input is a data URL → URL constructor fails when input is a data URL without a comma

The URL standard doesn't seem to reference RFC 2397 nor require a valid data URI.

Edit: There are several relevant WPT test failures https://searchfox.org/mozilla-central/rev/2c0a60b5b065ae0fdfcfae168141e82b834fb2d4/testing/web-platform/meta/url/url-constructor.html.ini

Yeah, this is a bug in Firefox not using a compliant URL parser (one that covers all schemes and does not dispatch on a per-scheme basis).

Depends on: url
Flags: needinfo?(dd.mozilla)
Flags: needinfo?(annevk)

Valentin, do you have time to take a look?

Flags: needinfo?(valentin.gosu)

The fix seems simple enough.

Assignee: nobody → valentin.gosu
Flags: needinfo?(valentin.gosu)
Priority: -- → P2
Pushed by valentin.gosu@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/d0fb6559c22e
URL constructor fails when input is a data URL without a comma r=baku
Pushed by valentin.gosu@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/db3536d46c35
URL constructor fails when input is a data URL without a comma r=baku
Flags: needinfo?(valentin.gosu)
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla71
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: