Skip to content

Improve the filename extension detection in MediaAnnotation.prototype._getContentType - #21887

Open
Snuffleupagus wants to merge 1 commit into
mozilla:masterfrom
Snuffleupagus:MediaAnnotation-ext
Open

Improve the filename extension detection in MediaAnnotation.prototype._getContentType#21887
Snuffleupagus wants to merge 1 commit into
mozilla:masterfrom
Snuffleupagus:MediaAnnotation-ext

Conversation

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

Rather than splitting the filename into an Array, and then take its last element, we can directly search for the last dot instead.

Doing this also fixes what appears to be a small oversight, since the current code may find a "valid" extension when one doesn't actually exist in the filename. For example, try running the following code in the console:

var filename = "mp4";
filename.split(".").at(-1)?.toLowerCase();

…e._getContentType`

Rather than splitting the filename into an Array, and then take its last element, we can directly search for the *last* dot instead.

Doing this also fixes what appears to be a small oversight, since the current code may find a "valid" extension when one doesn't actually exist in the filename. For example, try running the following code in the console:
```js
var filename = "mp4";
filename.split(".").at(-1)?.toLowerCase();
```
@codecov-commenter

codecov-commenter commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (716aff9) to head (a754b49).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21887   +/-   ##
=======================================
  Coverage   90.28%   90.29%           
=======================================
  Files         264      264           
  Lines       67273    67274    +1     
=======================================
+ Hits        60737    60742    +5     
+ Misses       6536     6532    -4     
Flag Coverage Δ
browsertest 66.31% <0.00%> (-0.01%) ⬇️
fonttest 8.92% <ø> (ø)
integrationtest 69.43% <0.00%> (+<0.01%) ⬆️
unittest 58.47% <100.00%> (+<0.01%) ⬆️
unittestcli 57.02% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants