Skip to content

Commit 483c668

Browse files
committed
fix(validation): empty files are not rejected
fixes FineUploader#1381
1 parent eca1c2a commit 483c668

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

client/js/upload-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ qq.UploadData = function(uploaderProxy) {
7474
name: spec.name,
7575
originalName: spec.name,
7676
uuid: spec.uuid,
77-
size: spec.size || -1,
77+
size: spec.size == null ? -1 : spec.size,
7878
status: status
7979
}) - 1;
8080

test/unit/resources/empty.txt

Whitespace-only changes.

test/unit/submit-validate-cancel.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ if (qqtest.canDownloadFileAsBlob) {
244244
});
245245

246246
describe("file rejection via internal validation", function() {
247-
function setupUploader(limits, numBlobs, statusChangeLogic) {
247+
function setupUploader(limits, numBlobsOrTheBlob, statusChangeLogic) {
248248
var uploader = new qq.FineUploaderBasic({
249249
autoUpload: false,
250250
validation: limits,
@@ -255,19 +255,24 @@ if (qqtest.canDownloadFileAsBlob) {
255255
}
256256
});
257257

258-
qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
259-
numBlobs = [].concat(numBlobs);
260-
qq.each(numBlobs, function(idx, num) {
261-
var blobs = [],
262-
i;
263-
264-
for (i = 0; i < num; i++) {
265-
blobs.push(blob);
266-
}
258+
if (qq.isBlob(numBlobsOrTheBlob)) {
259+
uploader.addFiles(numBlobsOrTheBlob);
260+
}
261+
else {
262+
qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
263+
numBlobsOrTheBlob = [].concat(numBlobsOrTheBlob);
264+
qq.each(numBlobsOrTheBlob, function(idx, num) {
265+
var blobs = [],
266+
i;
267+
268+
for (i = 0; i < num; i++) {
269+
blobs.push(blob);
270+
}
267271

268-
uploader.addFiles(blobs);
272+
uploader.addFiles(blobs);
273+
});
269274
});
270-
});
275+
}
271276
}
272277

273278
it("prevents too many items from being submitted at once", function(done) {
@@ -318,6 +323,18 @@ if (qqtest.canDownloadFileAsBlob) {
318323
});
319324
});
320325

326+
it("prevents empty files from being submitted", function(done) {
327+
qqtest.downloadFileAsBlob("empty.txt", "text/plain").then(function(emptyFile) {
328+
setupUploader({}, emptyFile, function(id, oldStatus, newStatus) {
329+
if (newStatus === qq.status.REJECTED) {
330+
assert.equal(this.getUploads().length, 1);
331+
assert.equal(this.getUploads({status: qq.status.REJECTED}).length, 1);
332+
done();
333+
}
334+
});
335+
});
336+
});
337+
321338
it("prevents files that are too large from being submitted", function(done) {
322339
setupUploader({sizeLimit: 3265}, 1, function(id, oldStatus, newStatus) {
323340
if (newStatus === qq.status.REJECTED) {

0 commit comments

Comments
 (0)