Skip to content

Commit

Permalink
Merge pull request #123 from alexindigo/v1.0.0-rc2
Browse files Browse the repository at this point in the history
#109 Append proper line break
  • Loading branch information
alexindigo committed Jul 22, 2015
2 parents 7e7df9c + 1cbe33b commit 9f29fef
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/form_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ FormData.prototype._multiPartFooter = function(field, value, options) {
};

FormData.prototype._lastBoundary = function() {
return '--' + this.getBoundary() + '--';
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
};

FormData.prototype.getHeaders = function(userHeaders) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
"name": "form-data",
"description": "A module to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
"version": "1.0.0-rc1",
"version": "1.0.0-rc2",
"repository": {
"type": "git",
"url": "git://github.com/felixge/node-form-data.git"
Expand Down
51 changes: 51 additions & 0 deletions test/integration/test-last_boundary-line_break.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var http = require('http');
var common = require('../common');
var assert = common.assert;
var FormData = require(common.dir.lib + '/form_data');
var server;

function submitForm() {

var form = new FormData();

form.append('field', 'value');

form.submit('http://localhost:' + common.port + '/', function(err, res) {

if (err) {
throw err;
}

assert.strictEqual(res.statusCode, 200);

// unstuck new streams
res.resume();

server.close();
});
}

// create https server
server = http.createServer(function(req, res) {

var body = '';

req.setEncoding('utf8');

// old and simple
req.on('data', function(data) {
body += data;
});

req.on('end', function()
{
// last character(s) sequence equals predefined line break
assert.strictEqual(body.substr(-1 * FormData.LINE_BREAK.length), FormData.LINE_BREAK);

res.writeHead(200);
res.end();
});
});

// when https server ready submit form
server.listen(common.port, submitForm);

0 comments on commit 9f29fef

Please sign in to comment.