Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formidable

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formidable - npm Package Compare versions

Comparing version 1.0.13 to 1.0.14

16

lib/file.js

@@ -26,2 +26,4 @@ if (global.GENTLY) require = GENTLY.hijack(require);

this.hash = crypto.createHash(properties.hash);
} else {
this.hash = null;
}

@@ -51,8 +53,6 @@ }

var self = this;
if (self.hash) {
self.hash.update(buffer);
}
this._writeStream.write(buffer, function() {
if (self.hash) {
if (self.hash.hasOwnProperty('update')) {
self.hash.update(buffer);
}
}
self.lastModifiedDate = new Date();

@@ -67,6 +67,6 @@ self.size += buffer.length;

var self = this;
if (self.hash) {
self.hash = self.hash.digest('hex');
}
this._writeStream.end(function() {
if(self.hash) {
self.hash = self.hash.digest('hex');
}
self.emit('end');

@@ -73,0 +73,0 @@ cb();

@@ -77,2 +77,25 @@ if (global.GENTLY) require = GENTLY.hijack(require);

// Setup callback first, so we don't miss anything from data events emitted
// immediately.
if (cb) {
var fields = {}, files = {};
this
.on('field', function(name, value) {
fields[name] = value;
})
.on('file', function(name, file) {
files[name] = file;
})
.on('error', function(err) {
cb(err, fields, files);
})
.on('end', function() {
cb(null, fields, files);
});
}
// Parse headers and setup the parser, ready to start listening for data.
this.writeHeaders(req.headers);
// Start listening for data.
var self = this;

@@ -101,21 +124,2 @@ req

if (cb) {
var fields = {}, files = {};
this
.on('field', function(name, value) {
fields[name] = value;
})
.on('file', function(name, file) {
files[name] = file;
})
.on('error', function(err) {
cb(err, fields, files);
})
.on('end', function() {
cb(null, fields, files);
});
}
this.writeHeaders(req.headers);
return this;

@@ -281,5 +285,10 @@ };

IncomingForm.prototype._parseContentLength = function() {
this.bytesReceived = 0;
if (this.headers['content-length']) {
this.bytesReceived = 0;
this.bytesExpected = parseInt(this.headers['content-length'], 10);
} else if (this.headers['transfer-encoding'] === undefined) {
this.bytesExpected = 0;
}
if (this.bytesExpected !== null) {
this.emit('progress', this.bytesReceived, this.bytesExpected);

@@ -286,0 +295,0 @@ }

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/felixge/node-formidable",
"version": "1.0.13",
"version": "1.0.14",
"devDependencies": {

@@ -24,3 +24,3 @@ "gently": "0.8.0",

"engines": {
"node": "<0.9.0"
"node": ">=0.8.0"
},

@@ -27,0 +27,0 @@ "repository": {

@@ -263,2 +263,9 @@ # Formidable

### v1.0.14
* Add failing hash tests. (Ben Trask)
* Enable hash calculation again (Eugene Girshov)
* Test for immediate data events (Tim Smart)
* Re-arrange IncomingForm#parse (Tim Smart)
### v1.0.13

@@ -269,2 +276,3 @@

* Bumping build node versions (Sven Lito)
* Additional fix for empty requests (Eugene Girshov)
* Change the default to 1000, to match the new Node behaviour. (OrangeDog)

@@ -271,0 +279,0 @@ * Add ability to control maxKeys in the querystring parser. (OrangeDog)

module.exports['menu_seperator.png.http'] = [
{type: 'file', name: 'image', filename: 'menu_separator.png', fixture: 'menu_separator.png'}
{type: 'file', name: 'image', filename: 'menu_separator.png', fixture: 'menu_separator.png',
sha1: 'c845ca3ea794be298f2a1b79769b71939eaf4e54'}
];
module.exports['beta-sticker-1.png.http'] = [
{type: 'file', name: 'sticker', filename: 'beta-sticker-1.png', fixture: 'beta-sticker-1.png'}
{type: 'file', name: 'sticker', filename: 'beta-sticker-1.png', fixture: 'beta-sticker-1.png',
sha1: '6abbcffd12b4ada5a6a084fe9e4584f846331bc4'}
];
module.exports['blank.gif.http'] = [
{type: 'file', name: 'file', filename: 'blank.gif', fixture: 'blank.gif'}
{type: 'file', name: 'file', filename: 'blank.gif', fixture: 'blank.gif',
sha1: 'a1fdee122b95748d81cee426d717c05b5174fe96'}
];
module.exports['binaryfile.tar.gz.http'] = [
{type: 'file', name: 'file', filename: 'binaryfile.tar.gz', fixture: 'binaryfile.tar.gz'}
{type: 'file', name: 'file', filename: 'binaryfile.tar.gz', fixture: 'binaryfile.tar.gz',
sha1: 'cfabe13b348e5e69287d677860880c52a69d2155'}
];
module.exports['plain.txt.http'] = [
{type: 'file', name: 'file', filename: 'plain.txt', fixture: 'plain.txt'}
{type: 'file', name: 'file', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'}
];

@@ -5,2 +5,3 @@ module.exports = {

'empty-multipart.http': [],
'minimal.http': [],
};
module.exports['generic.http'] = [
{type: 'file', name: 'upload', filename: '', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: '', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];
module.exports['filename-name.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];
module.exports['crlf.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];
module.exports['preamble.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];
module.exports['missing-hyphens1.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];
module.exports['missing-hyphens2.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872'},
];

@@ -50,4 +50,5 @@ var hashish = require('hashish');

if (parsedPart.type === 'file') {
var filename = parsedPart.value.name;
assert.equal(filename, expectedPart.filename);
var file = parsedPart.value;
assert.equal(file.name, expectedPart.filename);
if(expectedPart.sha1) assert.equal(file.hash, expectedPart.sha1);
}

@@ -64,2 +65,3 @@ });

form.uploadDir = common.dir.tmp;
form.hash = "sha1";
form.parse(req);

@@ -66,0 +68,0 @@

@@ -65,5 +65,9 @@ var common = require('../common');

var events = ['error', 'aborted', 'data', 'end'];
gently.expect(REQ, 'on', events.length, function(event, fn) {
assert.equal(event, events.shift());
gently.expect(form, 'writeHeaders', function(headers) {
assert.strictEqual(headers, REQ.headers);
});
var EVENTS = ['error', 'aborted', 'data', 'end'];
gently.expect(REQ, 'on', EVENTS.length, function(event, fn) {
assert.equal(event, EVENTS.shift());
emit[event] = fn;

@@ -73,6 +77,2 @@ return this;

gently.expect(form, 'writeHeaders', function(headers) {
assert.strictEqual(headers, REQ.headers);
});
form.parse(REQ);

@@ -201,6 +201,2 @@

gently.expect(REQ, 'on', 4, function() {
return this;
});
gently.expect(form, 'on', 4, function(event, fn) {

@@ -225,2 +221,8 @@ if (event == 'field') {

gently.expect(form, 'writeHeaders');
gently.expect(REQ, 'on', 4, function() {
return this;
});
var parseCbOk = function (err, fields, files) {

@@ -230,7 +232,3 @@ assert.deepEqual(fields, {field1: 'bar', field2: 'nice'});

};
gently.expect(form, 'writeHeaders');
form.parse(REQ, parseCbOk);
gently.expect(REQ, 'on', 4, function() {
return this;
});

@@ -247,2 +245,5 @@ var ERR = new Error('test');

gently.expect(form, 'writeHeaders');
gently.expect(REQ, 'on', 4, function() {
return this;
});
}

@@ -257,2 +258,21 @@ return this;

})();
(function testWriteOrder() {
gently.expect(EventEmitterStub, 'call');
var form = new IncomingForm();
var REQ = new events.EventEmitter();
var BUF = {};
var DATACB = null;
REQ.on('newListener', function(event, fn) {
if ('data' === event) fn(BUF);
});
gently.expect(form, 'writeHeaders');
gently.expect(form, 'write', function(buf) {
assert.strictEqual(buf, BUF);
});
form.parse(REQ);
})();
});

@@ -388,5 +408,8 @@

form.headers = {};
gently.expect(form, 'emit', function(event, bytesReceived, bytesExpected) {
assert.equal(event, 'progress');
assert.equal(bytesReceived, 0);
assert.equal(bytesExpected, 0);
});
form._parseContentLength();
assert.strictEqual(form.bytesReceived, null);
assert.strictEqual(form.bytesExpected, null);

@@ -393,0 +416,0 @@ form.headers['content-length'] = '8';

@@ -44,3 +44,3 @@ var common = require('../common');

assert.ok(uploads['shortest_video.flv'].progress.length > 3);
assert.equal(uploads['shortest_video.flv'].file.hash, 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
assert.equal(uploads['shortest_video.flv'].file.hash, 'd6a17616c7143d1b1438ceeef6836d1a09186b3a');
assert.equal(uploads['shortest_video.flv'].progress.slice(-1), uploads['shortest_video.flv'].file.size);

@@ -50,3 +50,3 @@ assert.ok(uploads['shortest_video.mp4']);

assert.ok(uploads['shortest_video.mp4'].progress.length > 3);
assert.equal(uploads['shortest_video.mp4'].file.hash, 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
assert.equal(uploads['shortest_video.mp4'].file.hash, '937dfd4db263f4887ceae19341dcc8d63bcd557f');

@@ -53,0 +53,0 @@ server.close();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc