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); }; diff --git a/www/ponyfills.js b/www/ponyfills.js index e49e6d7..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 || ''; + 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 +};