-
Notifications
You must be signed in to change notification settings - Fork 476
Closes #9821 - DownloadService will use a default mime type if otherwise empty #9822
Closes #9821 - DownloadService will use a default mime type if otherwise empty #9822
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9822 +/- ##
===========================================
Coverage 74.06% 74.07%
+ Complexity 5656 5056 -600
===========================================
Files 772 702 -70
Lines 28763 25601 -3162
Branches 4741 4203 -538
===========================================
- Hits 21303 18963 -2340
+ Misses 4981 4430 -551
+ Partials 2479 2208 -271
Continue to review full report at Codecov.
|
| internal fun getNotEmptyMimeType(mimeType: String?) = if (!mimeType.isNullOrEmpty()) { | ||
| mimeType | ||
| } else { | ||
| "*/*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could re-use getSafeContentType that has the same logic plus it tries to extract the MimeTypefrom the physical file, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this new safety net allows for a quick and easy way to ensure we don't get that crash anymore.
Using getSafeContentType would mean taking another stab at inferring the mime type (which I would've preferred to not do if not neded (it is a bit of code executed..) but maybe it would help reducing the number of times */* is returned).
In the current implementation getSafeContentType returns DownloadUtils.sanitizeMimeType(resultContentType) ?: "*/*" and so it still has the possibility of returning an empty String.
Instead of wrapping getSafeContentType and others in getNotEmptyMimeType we could add one last check for empty strings in that method and use that.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the patch to use getSafeContentType.
Would appreciate if you could comment on the approach, if it's okay.
I'll work next on updating tests and documentation.
|
This pull request has conflicts when rebasing. Could you fix it @Mugurell? 🙏 |
a598e73 to
022af9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, could we add tests for the new extension function.
components/support/ktx/src/main/java/mozilla/components/support/ktx/kotlin/String.kt
Show resolved
Hide resolved
…type if otherwise empty Speculative fix (cannot reproduce the issue) for crashes where based on the stacktrace the download's mime type was empty.
022af9c to
67b4c71
Compare
Speculative fix (cannot reproduce the issue) for crashes where based on the
stacktrace the download's mime type was empty.
Pull Request checklist
After merge