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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sms/index.html
Expand Up @@ -35,6 +35,7 @@
<script defer src="shared/js/notification_helper.js"></script>
<script defer src="shared/js/gesture_detector.js"></script>
<script defer src="shared/js/settings_url.js"></script>
<script defer src="shared/js/mime_mapper.js"></script>
-->
<script defer src="shared/js/lazy_loader.js"></script>
<script defer src="js/startup.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion apps/sms/js/attachment.js
Expand Up @@ -218,7 +218,8 @@
name: 'open',
data: {
type: this.blob.type,
filename: this.name,
filename:
MimeMapper.ensureFilenameMatchesType(this.name, this.blob.type),
blob: this.blob,
allowSave: options && options.allowSave
}
Expand Down
1 change: 1 addition & 0 deletions apps/sms/js/startup.js
Expand Up @@ -9,6 +9,7 @@ var lazyLoadFiles = [
'shared/js/notification_helper.js',
'shared/js/gesture_detector.js',
'shared/js/settings_url.js',
'shared/js/mime_mapper.js',
'js/dialog.js',
'js/blacklist.js',
'js/contacts.js',
Expand Down
15 changes: 15 additions & 0 deletions shared/js/mime_mapper.js
Expand Up @@ -89,5 +89,20 @@ var MimeMapper = {

guessTypeFromExtension: function(extension) {
return this._extensionToTypeMap[extension];
},

isFilenameMatchesType: function(filename, mimetype) {
var array = filename.split('.');
var extension = array[array.length - 1];
var guessedType = this.guessTypeFromExtension(extension);
return (guessedType == mimetype);
},

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.

var guessedExt = this.guessExtensionFromType(mimetype);
filename += '.' + guessedExt;
}
return filename;
}
};