Skip to content

Commit

Permalink
Merge pull request #2208 from simov/form-data-null
Browse files Browse the repository at this point in the history
Update to form-data RC4 and pass null values to it
  • Loading branch information
simov committed May 10, 2016
2 parents 11a1c72 + dd3fad0 commit 8add02c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"combined-stream": "~1.0.5",
"extend": "~3.0.0",
"forever-agent": "~0.6.1",
"form-data": "~1.0.0-rc3",
"form-data": "~1.0.0-rc4",
"har-validator": "~2.0.6",
"hawk": "~3.1.3",
"http-signature": "~1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion request.js
Expand Up @@ -336,7 +336,7 @@ Request.prototype.init = function (options) {
var formData = options.formData
var requestForm = self.form()
var appendFormValue = function (key, value) {
if (value.hasOwnProperty('value') && value.hasOwnProperty('options')) {
if (value && value.hasOwnProperty('value') && value.hasOwnProperty('options')) {
requestForm.append(key, value.value, value.options)
} else {
requestForm.append(key, value)
Expand Down
14 changes: 14 additions & 0 deletions tests/test-form-data-error.js
Expand Up @@ -65,6 +65,20 @@ tape('omit content-length header if the value is set to NaN', function(t) {
})
})

// TODO: remove this test after form-data@2.0 starts stringifying null values
tape('form-data should throw on null value', function (t) {
t.throws(function () {
request({
method: 'POST',
url: 'http://localhost:6767',
formData: {
key: null
}
})
}, /Cannot read property 'path' of null/)
t.end()
})

tape('cleanup', function(t) {
s.close(function() {
t.end()
Expand Down

0 comments on commit 8add02c

Please sign in to comment.