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

Commit

Permalink
Bug 909622 - [B2G][Helix][messages][zhaotao]Sending mms with attachme…
Browse files Browse the repository at this point in the history
…nt(chinese name mp3) fail - r=julienw

- Replace all non standard word characters in filenames with a # while encoding SMIL
- Remove HTML escaping in preference for replacing unsafe chars with the #
- Add unit test to ensure that quotes are always escaped
  • Loading branch information
gnarf committed Sep 23, 2013
1 parent cd3a11c commit c662562
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apps/sms/js/smil.js
Expand Up @@ -5,7 +5,8 @@
(function() {
'use strict';

var runsafefilename = /[^a-zA-Z0-9.]/g;
// characters not allowed in smil filenames
var unsafeFilenamePattern = /[^a-zA-Z0-9_#.()?&%-]/g;

// This encoder is aimed for encoding the string by 'utf-8'.
var encoder = new TextEncoder('UTF-8');
Expand Down Expand Up @@ -65,9 +66,9 @@ function SMIL_generateSlides(data, slide, slideIndex) {
if (slide.blob) {
blobType = Utils.typeFromMimeType(slide.blob.type);
if (blobType) {
name = slide.name.substr(slide.name.lastIndexOf('/') + 1);
// just to be safe, remove any non-standard characters from the filename
name = Template.escape(slide.name);
name = name.substr(name.lastIndexOf('/') + 1);
name = name.replace(unsafeFilenamePattern, '#');
name = SMIL_generateUniqueLocation(data, name);
media = '<' + blobType + ' src="' + name + '" region="Image"/>';
data.attachments.push({
Expand Down
36 changes: 36 additions & 0 deletions apps/sms/test/unit/smil_test.js
Expand Up @@ -450,6 +450,42 @@ suite('SMIL', function() {
}), filenames, 'List of filenames matches <img> tags');

});

test('Message with non-ascii filenames', function() {
var smilTest = [{
name: 'kitten♥-450.jpg',
blob: testImageBlob
}, {
// 5 replaced chars
name: '새끼고양이.jpg',
blob: testImageBlob
}, {
// 5 replaced chars
name: 'ἀρετή.jpg',
blob: testImageBlob
}, {
// testing non-replaced chars
name: 'abzABZ019_#.()?&%-.jpg',
blob: testImageBlob
}, {
// quotes MUST be replaced - filename content is used in xml
name: '"\'.jpg',
blob: testImageBlob
}];
var output = SMIL.generate(smilTest);
assert.equal(output.attachments.length, 5);
assert.equal(output.attachments[0].location, 'kitten#-450.jpg');

// output from the next two also tests a clash after replace
assert.equal(output.attachments[1].location, '#####.jpg');
assert.equal(output.attachments[2].location, '#####_2.jpg');

// this one has nothing to replace:
assert.equal(output.attachments[3].location, smilTest[3].name);

// quotes must be replaced
assert.equal(output.attachments[4].location, '##.jpg');
});
});

});

0 comments on commit c662562

Please sign in to comment.