Closed Bug 1845006 Opened 1 year ago Closed 1 year ago

Fix a few intertwined bugs with data URL parsing (double-parsing of the mime type, not fully serializing them, and doubling of charsets in content-type headers)

Categories

(Core :: Networking, defect, P2)

defect

Tracking

()

RESOLVED FIXED
118 Branch
Tracking Status
firefox118 --- fixed

People

(Reporter: twisniewski, Assigned: twisniewski)

References

Details

(Whiteboard: [necko-triaged])

Attachments

(1 file)

Basically, we already parse the mime type part of the URL here: https://searchfox.org/mozilla-central/source/netwerk/protocol/data/nsDataChannel.cpp#61
But SetContentType and SetContentCharset at the end of the function will also re-parse the result, using our older parser which isn't saving the parameters of the mime type: https://searchfox.org/mozilla-central/source/netwerk/protocol/data/nsDataChannel.cpp#102-103
We should just set mContentType and mContentCharset in the first line above.

Per spec we should also be serializing the full resulting mimetype here, not just getting its essence: https://searchfox.org/mozilla-central/source/netwerk/protocol/data/nsDataHandler.cpp#189

Finally, the fetch and XHR code doubles-up the charset needlessly in these spots, so we should tell it to only add the charset if it's not already present:

Summary: Use CMimeType::Parse in nsBaseChannel::setContentType, instead of net_ParseContentType → Fix a few bugs with data URL parsing (double-parsing of the mime type, not fully serializing them, and doubling of charsets in content-type headers)
Summary: Fix a few bugs with data URL parsing (double-parsing of the mime type, not fully serializing them, and doubling of charsets in content-type headers) → Fix a few intertwined bugs with data URL parsing (double-parsing of the mime type, not fully serializing them, and doubling of charsets in content-type headers)
Severity: -- → S3
Priority: -- → P2
Whiteboard: [necko-triaged]

It turns out that too much Gecko code relies on whatever "content type" happens to mean right now, which is not "whatever is specified by the data url as per the spec", but seems to be more along the lines of the essence of the MimeType (more or less). As such it's too risky to change all of that, so I've taken a new approach:

  • update our data url parsing code to follow the spec text more closely to pass these WPTs.
  • have it put the full MimeType in a new instance var on the data url channel
  • have XHR/fetch use that new value for content-type response headers on data urls.

New try run here: https://treeherder.mozilla.org/jobs?repo=try&revision=657429472db615aa68036814b8e8ead2a51409f5

Assignee: nobody → twisniewski
Status: NEW → ASSIGNED
Pushed by twisniewski@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8d98996f824c store the fully-serialized MimeType on data url channels so XHR and fetch may use it for content-type response headers, and clean up the data url parsing code to better match the spec. r=kershaw,sunil,necko-reviewers

Ah, apologies. This is a quick fix I should have caught by rebuilding first after rebasing, then landing. Fix incoming later today.

Flags: needinfo?(twisniewski)
Pushed by twisniewski@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f96e24bbd71c store the fully-serialized MimeType on data url channels so XHR and fetch may use it for content-type response headers, and clean up the data url parsing code to better match the spec. r=kershaw,sunil,necko-reviewers
Pushed by twisniewski@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0d9bc1bc0799 store the fully-serialized MimeType on data url channels so XHR and fetch may use it for content-type response headers, and clean up the data url parsing code to better match the spec. r=kershaw,sunil,necko-reviewers
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 118 Branch
Flags: needinfo?(twisniewski)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: