Bug 1690051 - Make browser.download.sanitize_non_media_extensions work and test it. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D103695
This commit is contained in:
Tom Schuster 2021-02-03 10:55:33 +00:00
parent 063f86bbb1
commit 9011e911cf
6 changed files with 37 additions and 3 deletions

View File

@ -161,6 +161,9 @@ skip-if = (verify && debug && (os == 'linux'))
[browser_bug664672.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_bug676619.js]
support-files =
dummy.ics
dummy.ics^headers^
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_bug710878.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.

View File

@ -92,6 +92,20 @@ async function runTest(url) {
let oggExtension = getMIMEInfoForType("application/ogg").primaryExtension;
await testLink("link13", "no file extension." + oggExtension);
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1690051#c8
if (AppConstants.platform != "win") {
const PREF = "browser.download.sanitize_non_media_extensions";
ok(Services.prefs.getBoolPref(PREF), "pref is set before");
// Check that ics (iCal) extension is changed/fixed when the pref is true.
await testLink("link14", "dummy.ics");
// And not changed otherwise.
Services.prefs.setBoolPref(PREF, false);
await testLink("link14", "dummy.not-ics");
Services.prefs.clearUserPref(PREF);
}
BrowserTestUtils.removeTab(tab);
}

View File

@ -35,6 +35,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=676619
download="example.com" id="link12" target="_blank">Download "example.com"</a></li>
<li><a href="video.ogg"
download="no file extension" id="link13">Download "force extension"</a></li>
<li><a href="dummy.ics"
download="dummy.not-ics" id="link14">Download "dummy.not-ics"</a></li>
</ul>
<div id="unload-flag">Okay</div>

View File

@ -0,0 +1,13 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
GEO:48.85299;2.36885
END:VEVENT
END:VCALENDAR

View File

@ -0,0 +1 @@
Content-Type: text/calendar

View File

@ -1367,10 +1367,11 @@ bool nsExternalAppHandler::ShouldForceExtension(const nsString& aFileExt) {
break;
}
}
if (!canForce) {
return false;
}
}
if (!canForce) {
return false;
}
// If we get here, we know for sure the mimetype allows us to overwrite the
// existing extension, if it's wrong. Return whether the extension is wrong: