Skip to content

Commit

Permalink
spec compliant incremental field parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed May 3, 2015
1 parent 60586bc commit 05616c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var is = require('type-is')
var Busboy = require('busboy')
var extend = require('xtend')
var appendField = require('append-field')

var makeError = require('./lib/make-error')
var appendField = require('./lib/append-field')
var diskStorage = require('./storage/disk')
var memoryStorage = require('./storage/memory')

Expand Down
17 changes: 0 additions & 17 deletions lib/append-field.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"middleware"
],
"dependencies": {
"append-field": "~0.1.0",
"busboy": "~0.2.9",
"concat-stream": "^1.4.8",
"mkdirp": "~0.3.5",
"qs": "~1.2.2",
"type-is": "~1.5.2",
"xtend": "^4.0.0"
},
Expand All @@ -30,7 +30,8 @@
"fs-temp": "^0.1.2",
"mocha": "*",
"rimraf": "^2.2.8",
"standard": "^3.7.2"
"standard": "^3.7.2",
"testdata-w3c-json-form": "^0.2.0"
},
"engines": {
"node": ">= 0.10.0"
Expand Down
36 changes: 36 additions & 0 deletions test/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var stream = require('stream')
var util = require('./_util')
var multer = require('../')
var FormData = require('form-data')
var testData = require('testdata-w3c-json-form')

describe('Fields', function () {
var parser
Expand Down Expand Up @@ -95,4 +96,39 @@ describe('Fields', function () {
})
})

testData.forEach(function (test) {
it('should handle ' + test.name, function (done) {
var form = new FormData()

test.fields.forEach(function (field) {
form.append(field.key, field.value)
})

util.submitForm(parser, form, function (err, req) {
assert.ifError(err)
assert.deepEqual(req.body, test.expected)
done()
})
})
})

it('should convert arrays into objects', function (done) {
var form = new FormData()

form.append('obj[0]', 'a')
form.append('obj[2]', 'c')
form.append('obj[x]', 'yz')

util.submitForm(parser, form, function (err, req) {
assert.ifError(err)
assert.deepEqual(req.body, {
obj: {
'0': 'a',
'2': 'c',
'x': 'yz'
}
})
done()
})
})
})

0 comments on commit 05616c6

Please sign in to comment.