From 7b1d9100a277a3a5a22a7ba60fe2e1e1b56fc82a Mon Sep 17 00:00:00 2001 From: Narcis Beleuzu Date: Tue, 13 Oct 2020 17:56:47 +0300 Subject: [PATCH] Backed out changeset fc8c5c66f081 (bug 1667787) for mochitest failure test_invalidCharFileExtension.xhtml . CLOSED TREE --- .../downloads/test/browser/browser.ini | 4 - .../browser/browser_image_mimetype_issues.js | 113 ------------------ .../test/browser/not-really-a-jpeg.jpeg | Bin 42 -> 0 bytes .../browser/not-really-a-jpeg.jpeg^headers^ | 2 - .../general/browser_test_data_text_csv.js | 2 +- toolkit/content/contentAreaUtils.js | 10 -- .../exthandler/nsExternalHelperAppService.cpp | 48 ++------ 7 files changed, 14 insertions(+), 165 deletions(-) delete mode 100644 browser/components/downloads/test/browser/browser_image_mimetype_issues.js delete mode 100644 browser/components/downloads/test/browser/not-really-a-jpeg.jpeg delete mode 100644 browser/components/downloads/test/browser/not-really-a-jpeg.jpeg^headers^ diff --git a/browser/components/downloads/test/browser/browser.ini b/browser/components/downloads/test/browser/browser.ini index ac7ebdef9d29..15fdd9a632f7 100644 --- a/browser/components/downloads/test/browser/browser.ini +++ b/browser/components/downloads/test/browser/browser.ini @@ -10,10 +10,6 @@ support-files = !/toolkit/content/tests/browser/common/mockTransfer.js [browser_first_download_panel.js] skip-if = os == "linux" # Bug 949434 -[browser_image_mimetype_issues.js] -support-files = - not-really-a-jpeg.jpeg - not-really-a-jpeg.jpeg^headers^ [browser_overflow_anchor.js] skip-if = os == "linux" # Bug 952422 [browser_confirm_unblock_download.js] diff --git a/browser/components/downloads/test/browser/browser_image_mimetype_issues.js b/browser/components/downloads/test/browser/browser_image_mimetype_issues.js deleted file mode 100644 index f5231329a174..000000000000 --- a/browser/components/downloads/test/browser/browser_image_mimetype_issues.js +++ /dev/null @@ -1,113 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TEST_ROOT = getRootDirectory(gTestPath).replace( - "chrome://mochitests/content", - "http://example.com" -); - -var MockFilePicker = SpecialPowers.MockFilePicker; -MockFilePicker.init(window); - -/* - * Popular websites implement image optimization as serving files with - * extension ".jpg" but content type "image/webp". If we save such images, - * we should actually save them with a .webp extension as that is what - * they are. - */ - -/** - * Test the above with the "save image as" context menu. - */ -add_task(async function test_save_image_webp_with_jpeg_extension() { - await BrowserTestUtils.withNewTab( - `data:text/html,`, - async browser => { - let menu = document.getElementById("contentAreaContextMenu"); - let popupShown = BrowserTestUtils.waitForEvent(menu, "popupshown"); - BrowserTestUtils.synthesizeMouse( - "img", - 5, - 5, - { type: "contextmenu", button: 2 }, - browser - ); - await popupShown; - - await new Promise(resolve => { - MockFilePicker.showCallback = function(fp) { - ok( - fp.defaultString.endsWith("webp"), - `filepicker for image has "${fp.defaultString}", should end in webp` - ); - setTimeout(resolve, 0); - return Ci.nsIFilePicker.returnCancel; - }; - EventUtils.synthesizeMouseAtCenter( - menu.querySelector("#context-saveimage"), - {} - ); - }); - } - ); -}); - -/** - * Test with the "save link as" context menu. - */ -add_task(async function test_save_link_webp_with_jpeg_extension() { - await BrowserTestUtils.withNewTab( - `data:text/html,Nice image`, - async browser => { - let menu = document.getElementById("contentAreaContextMenu"); - let popupShown = BrowserTestUtils.waitForEvent(menu, "popupshown"); - BrowserTestUtils.synthesizeMouse( - "a[href]", - 5, - 5, - { type: "contextmenu", button: 2 }, - browser - ); - await popupShown; - - await new Promise(resolve => { - MockFilePicker.showCallback = function(fp) { - ok( - fp.defaultString.endsWith("webp"), - `filepicker for link has "${fp.defaultString}", should end in webp` - ); - setTimeout(resolve, 0); - return Ci.nsIFilePicker.returnCancel; - }; - EventUtils.synthesizeMouseAtCenter( - menu.querySelector("#context-savelink"), - {} - ); - }); - } - ); -}); - -/** - * Test with the main "save page" command. - */ -add_task(async function test_save_page_on_image_document() { - await BrowserTestUtils.withNewTab( - `${TEST_ROOT}/not-really-a-jpeg.jpeg?convert=webp`, - async browser => { - await new Promise(resolve => { - MockFilePicker.showCallback = function(fp) { - ok( - fp.defaultString.endsWith("webp"), - `filepicker for "save page" has "${fp.defaultString}", should end in webp` - ); - setTimeout(resolve, 0); - return Ci.nsIFilePicker.returnCancel; - }; - document.getElementById("Browser:SavePage").doCommand(); - }); - } - ); -}); diff --git a/browser/components/downloads/test/browser/not-really-a-jpeg.jpeg b/browser/components/downloads/test/browser/not-really-a-jpeg.jpeg deleted file mode 100644 index 04b7f003b463948d248755c4d6b19567941f8781..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 42 wcmWIYbaPW;U|NHDNp_}}r5y`kkp{eFRq|3j1*0P(*L3;+NC diff --git a/browser/components/downloads/test/browser/not-really-a-jpeg.jpeg^headers^ b/browser/components/downloads/test/browser/not-really-a-jpeg.jpeg^headers^ deleted file mode 100644 index c1a7794310b5..000000000000 --- a/browser/components/downloads/test/browser/not-really-a-jpeg.jpeg^headers^ +++ /dev/null @@ -1,2 +0,0 @@ -Content-Type: image/webp - diff --git a/dom/security/test/general/browser_test_data_text_csv.js b/dom/security/test/general/browser_test_data_text_csv.js index ad253e61a639..23a3e5576325 100644 --- a/dom/security/test/general/browser_test_data_text_csv.js +++ b/dom/security/test/general/browser_test_data_text_csv.js @@ -41,7 +41,7 @@ function test() { function(win) { is( win.document.getElementById("location").value, - ".csv", + "text/csv;foo,bar,foobar", "file name of download should match" ); win.close(); diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 9c097440748d..6543efbbb019 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -1149,16 +1149,6 @@ function getDefaultExtension(aFilename, aURI, aContentType) { return ""; } // temporary fix for bug 120327 - // For images, rely solely on the mime type if known. - // All the extension is going to do is lie to us. - if (aContentType?.startsWith("image/")) { - let mimeInfo = getMIMEInfoForType(aContentType, ""); - let exts = Array.from(mimeInfo.getFileExtensions()); - if (exts.length) { - return exts[0]; - } - } - // First try the extension from the filename var url = Cc["@mozilla.org/network/standard-url-mutator;1"] .createInstance(Ci.nsIURIMutator) diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index 40b7a00bf957..8e38cbf6e3fa 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -203,7 +203,6 @@ static bool GetFilenameAndExtensionFromChannel(nsIChannel* aChannel, bool handleExternally = false; uint32_t disp; nsresult rv = aChannel->GetContentDisposition(&disp); - bool gotFileNameFromURI = false; if (NS_SUCCEEDED(rv)) { aChannel->GetContentDispositionFilename(aFileName); if (disp == nsIChannel::DISPOSITION_ATTACHMENT) handleExternally = true; @@ -230,7 +229,6 @@ static bool GetFilenameAndExtensionFromChannel(nsIChannel* aChannel, nsAutoCString leafName; url->GetFileName(leafName); if (!leafName.IsEmpty()) { - gotFileNameFromURI = true; rv = UnescapeFragment(leafName, url, aFileName); if (NS_FAILED(rv)) { CopyUTF8toUTF16(leafName, aFileName); // use escaped name @@ -238,14 +236,14 @@ static bool GetFilenameAndExtensionFromChannel(nsIChannel* aChannel, } } - // If we have a filename and no extension, remove trailing dots from the - // filename and extract the extension if that is possible. - if (aExtension.IsEmpty() && !aFileName.IsEmpty()) { - // Windows ignores terminating dots. So we have to as well, so - // that our security checks do "the right thing" - aFileName.Trim(".", false); + // Extract Extension, if we have a filename; otherwise, + // truncate the string + if (aExtension.IsEmpty()) { + if (!aFileName.IsEmpty()) { + // Windows ignores terminating dots. So we have to as well, so + // that our security checks do "the right thing" + aFileName.Trim(".", false); - if (!gotFileNameFromURI || aAllowURLExtension) { // XXX RFindCharInReadable!! nsAutoString fileNameStr(aFileName); int32_t idx = fileNameStr.RFindChar(char16_t('.')); @@ -1293,32 +1291,12 @@ nsExternalAppHandler::nsExternalAppHandler( mSuggestedFileName.CompressWhitespace(); mTempFileExtension.CompressWhitespace(); - // After removing trailing whitespaces from the name, if we have a - // temp file extension, replace the file extension with it if: - // - there is no extant file extension (or it only consists of ".") - // - the extant file extension contains invalid characters, or - // - the extant file extension is not known by the mimetype. - bool knownExtension = false; - // Note that originalFileExt is either empty or consists of an - // extension *including the dot* which we need to remove: - bool haveBogusExtension = - mMimeInfo && !originalFileExt.IsEmpty() && - NS_SUCCEEDED(mMimeInfo->ExtensionExists( - Substring(NS_ConvertUTF16toUTF8(originalFileExt), 1), - &knownExtension)) && - !knownExtension; - if (!mTempFileExtension.IsEmpty() && - (originalFileExt.Length() == 0 || originalFileExt.EqualsLiteral(".") || - originalFileExt.FindCharInSet( - KNOWN_PATH_SEPARATORS FILE_ILLEGAL_CHARACTERS) != kNotFound || - haveBogusExtension)) { - int32_t pos = mSuggestedFileName.RFindChar('.'); - if (pos != kNotFound) { - mSuggestedFileName = - Substring(mSuggestedFileName, 0, pos) + mTempFileExtension; - } else { - mSuggestedFileName.Append(mTempFileExtension); - } + // Append after removing trailing whitespaces from the name. + if (originalFileExt.FindCharInSet( + KNOWN_PATH_SEPARATORS FILE_ILLEGAL_CHARACTERS) != kNotFound) { + // The file extension contains invalid characters and using it would + // generate an unusable file, thus use mTempFileExtension instead. + mSuggestedFileName.Append(mTempFileExtension); originalFileExt = mTempFileExtension; }