Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert numeric multipart bodies to string #2022

Merged
merged 3 commits into from Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/multipart.js
Expand Up @@ -68,6 +68,9 @@ Multipart.prototype.build = function (parts, chunked) {
var body = chunked ? new CombinedStream() : []

function add (part) {
if (typeof part === 'number') {
part = part.toString()
}
return chunked ? body.append(part) : body.push(new Buffer(part))
}

Expand Down
15 changes: 10 additions & 5 deletions tests/test-multipart.js
Expand Up @@ -41,20 +41,24 @@ function runTest(t, a) {
req.on('end', function() {
// check for the fields traces

// 1st field : my_field
// my_field
t.ok(data.indexOf('name: my_field') !== -1)
t.ok(data.indexOf(multipartData[0].body) !== -1)

// my_number
t.ok(data.indexOf('name: my_number') !== -1)
t.ok(data.indexOf(multipartData[1].body) !== -1)

// 2nd field : my_buffer
// my_buffer
t.ok(data.indexOf('name: my_buffer') !== -1)
t.ok(data.indexOf(multipartData[1].body) !== -1)
t.ok(data.indexOf(multipartData[2].body) !== -1)

// 3rd field : my_file
// my_file
t.ok(data.indexOf('name: my_file') !== -1)
// check for unicycle.jpg traces
t.ok(data.indexOf('2005:06:21 01:44:12') !== -1)

// 4th field : remote_file
// remote_file
t.ok(data.indexOf('name: remote_file') !== -1)
// check for http://localhost:6767/file traces
t.ok(data.indexOf('Photoshop ICC') !== -1)
Expand All @@ -73,6 +77,7 @@ function runTest(t, a) {
// @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8
multipartData = [
{name: 'my_field', body: 'my_value'},
{name: 'my_number', body: 1000},
{name: 'my_buffer', body: new Buffer([1, 2, 3])},
{name: 'my_file', body: fs.createReadStream(localFile)},
{name: 'remote_file', body: request('http://localhost:6767/file')}
Expand Down