Bug 895726 - Ensure valid filename when triggering Gallery view activity #11747
Conversation
// 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)) { |
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.
You can simplify the two lines above with
if (this.name.endsWith('.' + guessedExt))
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.
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).
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.
A file named ".jpeg" also works.
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.
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)) { |
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.
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).
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'm not sure to understand. With this code, a file named ".jpeg" will stay ".jpeg".
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.
Sorry I misunderstood the code, it's fine actually.
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. |
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.