Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Handling of empty header values and field data
This patch introduces two new events to the multipart parser: 'onHeaderEnd' and 'onHeadersEnd'. These make it much easier to properly handle the output of the parser. Another nice addition is a system test that verifies a complete upload from start to finish.
- Loading branch information
Showing
7 changed files
with
102 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test: | ||
@find test/{simple,integration}/test-*.js | xargs -n 1 -t node | ||
@find test/{simple,integration,system}/test-*.js | xargs -n 1 -t node | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require('../common'); | ||
var BOUNDARY = '---------------------------10102754414578508781458777923' | ||
, FIXTURE = TEST_FIXTURES+'/multi_video.upload' | ||
, fs = require('fs') | ||
, sys = require('sys') | ||
, http = require('http') | ||
, formidable = require('formidable') | ||
, server = http.createServer(); | ||
|
||
server.addListener('request', function(req, res) { | ||
var form = new formidable.IncomingForm() | ||
, files = {}; | ||
|
||
form.uploadDir = TEST_TMP; | ||
form.parse(req); | ||
|
||
form | ||
.addListener('field', function(field, value) { | ||
assert.equal(field, 'title'); | ||
assert.equal(value, ''); | ||
}) | ||
.addListener('file', function(field, file) { | ||
assert.equal(field, 'upload'); | ||
files[file.filename] = true; | ||
}) | ||
.addListener('end', function() { | ||
assert.deepEqual | ||
( files | ||
, { 'shortest_video.flv': true | ||
, 'shortest_video.mp4' :true | ||
} | ||
); | ||
server.close(); | ||
res.writeHead(200); | ||
res.end('good'); | ||
}); | ||
}); | ||
|
||
server.listen(TEST_PORT, function() { | ||
var client = http.createClient(TEST_PORT) | ||
, headers = {'content-type': 'multipart/form-data; boundary='+BOUNDARY} | ||
, request = client.request('POST', '/', headers) | ||
, fixture = new fs.ReadStream(FIXTURE); | ||
|
||
fixture | ||
.addListener('data', function(b) {; | ||
request.write(b); | ||
}) | ||
.addListener('end', function() { | ||
request.end(); | ||
}); | ||
}); |