diff --git a/components/support/utils/src/main/java/mozilla/components/support/utils/DownloadUtils.kt b/components/support/utils/src/main/java/mozilla/components/support/utils/DownloadUtils.kt index bcacd6670b5..e86d999d70e 100644 --- a/components/support/utils/src/main/java/mozilla/components/support/utils/DownloadUtils.kt +++ b/components/support/utils/src/main/java/mozilla/components/support/utils/DownloadUtils.kt @@ -125,6 +125,16 @@ object DownloadUtils { */ private val encodedSymbolPattern = Pattern.compile("%[0-9a-f]{2}|[0-9a-z!#$&+-.^_`|~]", Pattern.CASE_INSENSITIVE) + /** + * Keep aligned with desktop generic content types: + * https://searchfox.org/mozilla-central/source/browser/components/downloads/DownloadsCommon.jsm#208 + */ + private val GENERIC_CONTENT_TYPES = arrayOf( + "application/octet-stream", + "binary/octet-stream", + "application/unknown" + ) + /** * Guess the name of the file that should be downloaded. * @@ -146,7 +156,11 @@ object DownloadUtils { val sanitizedMimeType = sanitizeMimeType(mimeType) val fileName = if (extractedFileName.contains('.')) { - changeExtension(extractedFileName, sanitizedMimeType) + if (GENERIC_CONTENT_TYPES.contains(mimeType)) { + extractedFileName + } else { + changeExtension(extractedFileName, sanitizedMimeType) + } } else { extractedFileName + createExtension(sanitizedMimeType) } diff --git a/components/support/utils/src/test/java/mozilla/components/support/utils/DownloadUtilsTest.kt b/components/support/utils/src/test/java/mozilla/components/support/utils/DownloadUtilsTest.kt index e1989587145..e5d2777096f 100644 --- a/components/support/utils/src/test/java/mozilla/components/support/utils/DownloadUtilsTest.kt +++ b/components/support/utils/src/test/java/mozilla/components/support/utils/DownloadUtilsTest.kt @@ -107,6 +107,9 @@ class DownloadUtilsTest { assertEquals("file.html", DownloadUtils.guessFileName(null, null, "http://example.com/file", "text/html")) assertEquals("file.html", DownloadUtils.guessFileName(null, null, "http://example.com/file", "text/html; charset=utf-8")) assertEquals("file.txt", DownloadUtils.guessFileName(null, null, "http://example.com/file.txt", "text/html")) + assertEquals("file.data", DownloadUtils.guessFileName(null, null, "http://example.com/file.data", "application/octet-stream")) + assertEquals("file.data", DownloadUtils.guessFileName(null, null, "http://example.com/file.data", "binary/octet-stream")) + assertEquals("file.data", DownloadUtils.guessFileName(null, null, "http://example.com/file.data", "application/unknown")) } @Test diff --git a/docs/changelog.md b/docs/changelog.md index 96f26ee9842..973711d0ccb 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,10 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/.config.yml) +* **feature-downloads**: + * 🚒 Bug fixed [issue #9441](https://github.com/mozilla-mobile/android-components/issues/9441) - Don't ask for redundant system files permission if not required. + * 🚒 Bug fixed [issue #9526](https://github.com/mozilla-mobile/android-components/issues/9526) - Downloads with generic content types use the correct file extension. + # 72.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v71.0.0...v72.0.0) @@ -26,9 +30,6 @@ permalink: /changelog/ * **support-base** * ⚠️ **This is a breaking change**: Update the signature of `ActivityResultHandler.onActivityResult` to avoid conflict with internal Android APIs. -* **feature-downloads**: - * 🚒 Bug fixed [issue #9441](https://github.com/mozilla-mobile/android-components/issues/9441) - Don't ask for redundant system files permission if not required. - * **feature-addons** * 🚒 Bug fixed [issue #9484] https://github.com/mozilla-mobile/android-components/issues/9484) - Handle multiple add-ons update that require new permissions.