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

Commit

Permalink
Merge pull request #18718 from azasypkin/bug-995350-save-button
Browse files Browse the repository at this point in the history
Bug 995350 - [SMS] - Display Save button for attached image file name having hidden directories ".gallery/". r=julien
  • Loading branch information
BavarianTomcat authored and rvandermeulen committed Apr 29, 2014
1 parent ef63d26 commit 82915bc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/sms/js/attachment.js
Expand Up @@ -31,6 +31,9 @@
// (see bug 805114 for a similar issue in Gallery)
var MAX_THUMBNAIL_GENERATION_SIZE = 1.5 * 1024 * 1024; // 1.5MB

// Path to the folder that stores all saved attachments
const ATTACHMENT_FOLDER_PATH = 'sms-attachments/';


function Attachment(blob, options) {
options = options || {};
Expand Down Expand Up @@ -233,6 +236,11 @@
var mimetype =
MimeMapper.guessTypeFromFileProperties(this.name, this.blob.type);
var filename = MimeMapper.ensureFilenameMatchesType(this.name, mimetype);

// Override filename, so that every attachment that is saved via "open"
// activity will be placed in the single location.
filename = ATTACHMENT_FOLDER_PATH + getBaseName(filename);

var activity = new MozActivity({
name: 'open',
data: {
Expand Down Expand Up @@ -262,5 +270,15 @@
iframe.contentDocument.addEventListener('click', clickOnFrame);
}

/**
* Gets actual base file name (name.extension) from its path.
*/
function getBaseName(filePath) {
if (!filePath) {
throw new Error('Filepath is not defined!');
}
return filePath.substring(filePath.lastIndexOf('/') + 1);
}

exports.Attachment = Attachment;
}(this));
27 changes: 27 additions & 0 deletions apps/sms/test/unit/attachment_test.js
Expand Up @@ -261,6 +261,33 @@ suite('attachment_test.js', function() {
assert.equal(MockMozActivity.calls.length, 1);
});

test('Filename is overridden using single attachment folder', function() {
var attachment1 = new Attachment(testImageBlob, {
name: '/some_path/.hidden_folder/attachment1.jpg'
});

attachment1.view();

assert.equal(MockMozActivity.calls.length, 1);
assert.equal(
MockMozActivity.calls[0].data.filename,
'sms-attachments/attachment1.jpg'
);

var attachment2 = new Attachment(testImageBlob, {
name: 'attachment2.jpg'
});

attachment2.view();

assert.equal(MockMozActivity.calls.length, 2);
assert.equal(
MockMozActivity.calls[1].data.filename,
'sms-attachments/attachment2.jpg'
);

});

suite('Activity errors >', function() {
var activity;
setup(function() {
Expand Down

0 comments on commit 82915bc

Please sign in to comment.