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

Bug 895726 - Ensure valid filename when triggering Gallery view activity #11747

Closed
wants to merge 1 commit into from

Conversation

lissyx
Copy link
Contributor

@lissyx lissyx commented Aug 25, 2013

Gallery will be in charge of maybe saving the file that we are passing.
If we pass it a file that has no extension, trying to save inside the
'pictures' DeviceStorage will fail because of the missing extension. So
we check if the filename has one and if it does not, we force one by
guessing from mime type.

// not matching the mimetype, then we force the one guessed from mimetype.
var guessedExt = MimeMapper.guessExtensionFromType(this.blob.type);
var currentExt = this.name.match(/.*\.(.{3})$/);
if (!currentExt || (currentExt && currentExt[1] != guessedExt)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the two lines above with

if (this.name.endsWith('.' + guessedExt))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion, but it may have some issue when current extension is "jpeg" because it will not match the returning mimetype "jpg" and become " *.jpeg.jpg "(it still works but just looks weird). Another approach is we append the guessedExt only when currentExt is not exist(and replace currentExt with guessedExt to make sure the image is savable even the currentExt is invalid).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file named ".jpeg" also works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rik, this is a simpler way and I prefer to produce some weird names in some case than to risk having a broken feature.

… SMS

Gallery will be in charge of maybe saving the file that we are passing.
If it receives a file that has no extension, trying to save inside the
'pictures' DeviceStorage will fail because of the missing extension. So
before initiating a new MozActivity from the SMS app, we check if the
filename has one and if it does not, we force one by guessing from mime
type.
},

ensureFilenameMatchesType: function(filename, mimetype) {
if (!this.isFilenameMatchesType(filename, mimetype)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the discussion previously(and on bugzilla), it would be more appropriate to have one extension only instead of adding guess type after the old one like *.jpeg.jpg.

Maybe you could having an extension regExp to:

  • match the original extension.
  • replace the extension with guessedType(if original extension exist).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand. With this code, a file named ".jpeg" will stay ".jpeg".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misunderstood the code, it's fine actually.

@mozilla-autolander-deprecated
Copy link
Contributor

This pull request has been closed due to tree stability issues. Please rebase and re-open the pull request if you still need to land this. Ensure the gaia-try run is green before landing. Sorry for any inconvenience.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants