Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Closes #9526 guessFileName handle generic content types
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 authored and mergify[bot] committed Jan 28, 2021
1 parent a5a950f commit 1f6341b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down

0 comments on commit 1f6341b

Please sign in to comment.