From c0c1af5ee69ad9b53824e8057040ab675a2e575f Mon Sep 17 00:00:00 2001 From: Konstantinos Tsanakas Date: Thu, 25 Jun 2020 13:36:38 +0200 Subject: [PATCH 1/3] fix(): default filename for blob --- test/js-specs.js | 38 ++++++++++++++++++++++++++++++++++++++ test/mocks/File.mock.js | 2 +- www/helpers.js | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/test/js-specs.js b/test/js-specs.js index 1cd139c..10c6236 100644 --- a/test/js-specs.js +++ b/test/js-specs.js @@ -629,6 +629,44 @@ describe('Common helpers', function () { }); }); + it('processes data correctly when serializer "multipart" is configured and form data contains file value (filename set)', (cb) => { + const formData = new FormDataMock(); + formData.append('myFile', new BlobMock([testString], { type: 'application/octet-stream' }), 'file.name'); + + helpers.processData(formData, 'multipart', (data) => { + data.buffers.length.should.be.equal(1); + data.names.length.should.be.equal(1); + data.fileNames.length.should.be.equal(1); + data.types.length.should.be.equal(1); + + data.buffers[0].should.be.eql(testStringBase64); + data.names[0].should.be.equal('myFile'); + data.fileNames[0].should.be.equal('file.name'); + data.types[0].should.be.equal('application/octet-stream'); + + cb(); + }); + }); + + it('processes data correctly when serializer "multipart" is configured and form data contains file value (filename empty)', (cb) => { + const formData = new FormDataMock(); + formData.append('myFile', new BlobMock([testString], { type: 'application/octet-stream' }), ''); + + helpers.processData(formData, 'multipart', (data) => { + data.buffers.length.should.be.equal(1); + data.names.length.should.be.equal(1); + data.fileNames.length.should.be.equal(1); + data.types.length.should.be.equal(1); + + data.buffers[0].should.be.eql(testStringBase64); + data.names[0].should.be.equal('myFile'); + data.fileNames[0].should.be.equal(''); + data.types[0].should.be.equal('application/octet-stream'); + + cb(); + }); + }); + it('processes data correctly when serializer "raw" is configured', (cb) => { const byteArray = new Uint8Array([1, 2, 3]); helpers.processData(byteArray, 'raw', (data) => { diff --git a/test/mocks/File.mock.js b/test/mocks/File.mock.js index 9806262..9c19e7b 100644 --- a/test/mocks/File.mock.js +++ b/test/mocks/File.mock.js @@ -3,7 +3,7 @@ const BlobMock = require('./Blob.mock'); module.exports = class FileMock extends BlobMock { constructor(blob, fileName) { super(blob, { type: blob.type }); - this._fileName = fileName || ''; + this._fileName = fileName !== undefined ? fileName : 'blob'; this.__lastModifiedDate = new Date(); } diff --git a/www/helpers.js b/www/helpers.js index 805fcf7..b88d776 100644 --- a/www/helpers.js +++ b/www/helpers.js @@ -453,7 +453,7 @@ module.exports = function init(global, jsUtil, cookieHandler, messages, base64, reader.onload = function () { result.buffers.push(base64.fromArrayBuffer(reader.result)); result.names.push(entry.value[0]); - result.fileNames.push(entry.value[1].name || 'blob'); + result.fileNames.push(entry.value[1].name !== undefined ? entry.value[1].name : 'blob'); result.types.push(entry.value[1].type || ''); processFormDataIterator(iterator, textEncoder, result, onFinished); }; From ca5306cb477d7cfa014b1083ee9ae025c99deab8 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsanakas Date: Mon, 6 Jul 2020 15:23:02 +0200 Subject: [PATCH 2/3] fix(ponyfills): default filename for blob --- www/ponyfills.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/ponyfills.js b/www/ponyfills.js index e49e6d7..3b509a3 100644 --- a/www/ponyfills.js +++ b/www/ponyfills.js @@ -16,7 +16,7 @@ module.exports = function init(global) { } else if (global.Blob && value instanceof global.Blob) { // mimic File instance by adding missing properties value.lastModifiedDate = new Date(); - value.name = filename || ''; + value.name = fileName !== undefined ? fileName : 'blob'; } else { value = String(value); } From 7b4d37acd96c8026f4fac6c9b03caeb3cdf10bcb Mon Sep 17 00:00:00 2001 From: Konstantinos Tsanakas Date: Tue, 7 Jul 2020 11:03:36 +0200 Subject: [PATCH 3/3] Update www/ponyfills.js Co-authored-by: Sefa Ilkimen --- www/ponyfills.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/ponyfills.js b/www/ponyfills.js index 3b509a3..b13d774 100644 --- a/www/ponyfills.js +++ b/www/ponyfills.js @@ -16,7 +16,7 @@ module.exports = function init(global) { } else if (global.Blob && value instanceof global.Blob) { // mimic File instance by adding missing properties value.lastModifiedDate = new Date(); - value.name = fileName !== undefined ? fileName : 'blob'; + value.name = filename !== undefined ? filename : 'blob'; } else { value = String(value); } @@ -44,4 +44,4 @@ module.exports = function init(global) { } return interface; -}; \ No newline at end of file +};