Skip to content

Commit

Permalink
Return N/A if argument for formatSize contains non-numeric characters…
Browse files Browse the repository at this point in the history
…. formatSize can now handle GBs. Added some simple tests.
  • Loading branch information
jayarjo committed Jan 26, 2011
1 parent f6c813c commit 70d41c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Version 1.3.x (2011-01-xx)
Fixed measurements of browse_button element in order to size and position input[type=file] element to fit it fully.
Fixed Flash runtime behavior for multiple_select=false and other simpleUpload usage cases: basically new FileReference has to be created for every select dialog.
Fixed browser sniffer to match only Safari, for fakeSafariDragDrop (seems like Safari on Mac doesn't require it either).
Fixed so that ExternalInterface escape strings properly, before passing them to JS.
Fixed so that ExternalInterface escapes strings properly, before passing them to JS.
Fixed eventual reinitialization of flash/silverlight runtimes, especially for cases when object wrapper needed to be programmatically hidden and then shown again.
Fixed so that Plupload will now ignore files with duplicate names when adding to the queue, in one set. Mainly introduced to work around Safari on Windows bug (https://bugs.webkit.org/show_bug.cgi?id=37957).
Fixed bug, when final UploadProgress was firing after FileUploaded for Flash simpleUpload.
Expand Down
7 changes: 6 additions & 1 deletion src/javascript/plupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,14 @@
* @return {String} Formatted size string.
*/
formatSize : function(size) {
if (size === undef) {
if (size === undef || /\D/.test(size)) {
return plupload.translate('N/A');
}

// GB
if (size > 1073741824) {
return Math.round(size / 1073741824, 1) + " GB";
}

// MB
if (size > 1048576) {
Expand Down
21 changes: 21 additions & 0 deletions tests/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
});


test('parseSize', function() {
expect(6);

equals(plupload.parseSize(1024), 1024, 1024);
equals(plupload.parseSize('1024k'), 1048576, '"1024k"');
equals(plupload.parseSize('1024kb'), 1048576, '"1024kb"');
equals(plupload.parseSize('1024Kb'), 1048576, '"1024Kb"');
equals(plupload.parseSize('2mb'), 2097152, '"2mb"');
equals(plupload.parseSize('4gb'), 4294967296, '"4gb"');
});

test('formatSize', function() {
var undef;
//expect(6);

equals(plupload.formatSize(undef), 'N/A', 'undefined');
equals(plupload.formatSize('abcdefg'), 'N/A', '"abcdefg"');
equals(plupload.formatSize('4294967296'), '4 GB', '"4294967296"');

});

test('addEvent, removeEvent, removeAllEvents', function() {

expect(17);
Expand Down

0 comments on commit 70d41c2

Please sign in to comment.