Skip to content

Commit 86c7614

Browse files
authored
Merge branch 'master' into feature/qsAlways
2 parents 9644b1c + 480b1cf commit 86c7614

File tree

10 files changed

+188
-120
lines changed

10 files changed

+188
-120
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.nyc_output/
12
coverage/
23
node_modules/
34
npm-debug.log

.travis.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ node_js:
1010
- "5.12"
1111
- "6.17"
1212
- "7.10"
13-
- "8.16"
13+
- "8.17"
1414
- "9.11"
15-
- "10.16"
15+
- "10.19"
1616
- "11.15"
17-
- "12.7"
18-
sudo: false
17+
- "12.16"
18+
- "13.11"
1919
cache:
2020
directories:
2121
- node_modules
@@ -66,15 +66,19 @@ before_install:
6666
# Configure eslint for linting
6767
if node_version_lt '8.0'; then npm_remove_module_re '^eslint(-|$)'
6868
fi
69-
- |
70-
# Configure istanbul for coverage
71-
if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$'
72-
fi
7369
- |
7470
# Configure mocha for testing
7571
if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3'
7672
elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3'
7773
elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0'
74+
elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2'
75+
fi
76+
- |
77+
# Configure nyc for coverage
78+
if node_version_lt '0.10'; then npm_remove_module_re '^nyc$'
79+
elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2'
80+
elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0'
81+
elif node_version_lt '8.0' ; then npm_use_module 'nyc' '14.1.1'
7882
fi
7983
- |
8084
# Configure supertest for http calls
@@ -95,8 +99,8 @@ before_scrpt:
9599
npm -s ls ||:
96100
script:
97101
- |
98-
# Run test script, depending on istanbul install
99-
if npm_module_installed 'istanbul'; then npm run-script test-travis
102+
# Run test script, depending on nyc install
103+
if npm_module_installed 'nyc'; then npm run-script test-travis
100104
else npm test
101105
fi
102106
- |
@@ -105,8 +109,8 @@ script:
105109
fi
106110
after_script:
107111
- |
108-
# Upload coverage to coveralls if exists
109-
if [[ -e ./coverage/lcov.info ]]; then
112+
# Upload coverage to coveralls
113+
if [[ -d .nyc_output ]]; then
110114
npm install --save-dev coveralls@2
111-
coveralls < ./coverage/lcov.info
115+
nyc report --reporter=text-lcov | coveralls
112116
fi

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ unreleased
33

44
55
6+
67
78
9+
810
* deps: type-is@~1.6.18
911

1012
1.19.0 / 2019-04-25

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,15 @@ encoding of the request. The parsing can be aborted by throwing an error.
279279

280280
## Errors
281281

282-
The middlewares provided by this module create errors depending on the error
283-
condition during parsing. The errors will typically have a `status`/`statusCode`
284-
property that contains the suggested HTTP response code, an `expose` property
285-
to determine if the `message` property should be displayed to the client, a
286-
`type` property to determine the type of error without matching against the
287-
`message`, and a `body` property containing the read body, if available.
288-
289-
The following are the common errors emitted, though any error can come through
282+
The middlewares provided by this module create errors using the
283+
[`http-errors` module](https://www.npmjs.com/package/http-errors). The errors
284+
will typically have a `status`/`statusCode` property that contains the suggested
285+
HTTP response code, an `expose` property to determine if the `message` property
286+
should be displayed to the client, a `type` property to determine the type of
287+
error without matching against the `message`, and a `body` property containing
288+
the read body, if available.
289+
290+
The following are the common errors created, though any error can come through
290291
for various reasons.
291292

292293
### content encoding unsupported
@@ -297,6 +298,20 @@ contained an encoding but the "inflation" option was set to `false`. The
297298
`'encoding.unsupported'`, and the `charset` property will be set to the
298299
encoding that is unsupported.
299300

301+
### entity parse failed
302+
303+
This error will occur when the request contained an entity that could not be
304+
parsed by the middleware. The `status` property is set to `400`, the `type`
305+
property is set to `'entity.parse.failed'`, and the `body` property is set to
306+
the entity value that failed parsing.
307+
308+
### entity verify failed
309+
310+
This error will occur when the request contained an entity that could not be
311+
failed verification by the defined `verify` option. The `status` property is
312+
set to `403`, the `type` property is set to `'entity.verify.failed'`, and the
313+
`body` property is set to the entity value that failed verification.
314+
300315
### request aborted
301316

302317
This error will occur when the request is aborted by the client before reading

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
"http-errors": "1.7.3",
1717
"iconv-lite": "0.4.24",
1818
"on-finished": "~2.3.0",
19-
"qs": "6.9.1",
19+
"qs": "6.9.3",
2020
"raw-body": "2.4.1",
2121
"type-is": "~1.6.18"
2222
},
2323
"devDependencies": {
24-
"eslint": "6.0.0",
25-
"eslint-config-standard": "12.0.0",
26-
"eslint-plugin-import": "2.18.0",
27-
"eslint-plugin-markdown": "1.0.0",
28-
"eslint-plugin-node": "9.1.0",
24+
"eslint": "6.8.0",
25+
"eslint-config-standard": "14.1.1",
26+
"eslint-plugin-import": "2.20.1",
27+
"eslint-plugin-markdown": "1.0.2",
28+
"eslint-plugin-node": "9.2.0",
2929
"eslint-plugin-promise": "4.2.1",
30-
"eslint-plugin-standard": "4.0.0",
31-
"istanbul": "0.4.5",
30+
"eslint-plugin-standard": "4.0.1",
3231
"methods": "1.1.2",
33-
"mocha": "6.1.4",
34-
"safe-buffer": "5.1.2",
32+
"mocha": "7.1.1",
33+
"nyc": "15.0.0",
34+
"safe-buffer": "5.2.0",
3535
"supertest": "4.0.2"
3636
},
3737
"files": [
@@ -46,7 +46,7 @@
4646
"scripts": {
4747
"lint": "eslint --plugin markdown --ext js,md .",
4848
"test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/",
49-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/",
50-
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/"
49+
"test-cov": "nyc --reporter=html --reporter=text npm test",
50+
"test-travis": "nyc --reporter=text npm test"
5151
}
5252
}

test/body-parser.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ describe('bodyParser()', function () {
114114

115115
describe('with verify option', function () {
116116
it('should apply to json', function (done) {
117-
var server = createServer({ verify: function (req, res, buf) {
118-
if (buf[0] === 0x20) throw new Error('no leading space')
119-
} })
117+
var server = createServer({
118+
verify: function (req, res, buf) {
119+
if (buf[0] === 0x20) throw new Error('no leading space')
120+
}
121+
})
120122

121123
request(server)
122124
.post('/')
@@ -126,9 +128,11 @@ describe('bodyParser()', function () {
126128
})
127129

128130
it('should apply to urlencoded', function (done) {
129-
var server = createServer({ verify: function (req, res, buf) {
130-
if (buf[0] === 0x20) throw new Error('no leading space')
131-
} })
131+
var server = createServer({
132+
verify: function (req, res, buf) {
133+
if (buf[0] === 0x20) throw new Error('no leading space')
134+
}
135+
})
132136

133137
request(server)
134138
.post('/')

test/json.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,11 @@ describe('bodyParser.json()', function () {
390390
})
391391

392392
it('should error from verify', function (done) {
393-
var server = createServer({ verify: function (req, res, buf) {
394-
if (buf[0] === 0x5b) throw new Error('no arrays')
395-
} })
393+
var server = createServer({
394+
verify: function (req, res, buf) {
395+
if (buf[0] === 0x5b) throw new Error('no arrays')
396+
}
397+
})
396398

397399
request(server)
398400
.post('/')
@@ -402,9 +404,11 @@ describe('bodyParser.json()', function () {
402404
})
403405

404406
it('should error with type = "entity.verify.failed"', function (done) {
405-
var server = createServer({ verify: function (req, res, buf) {
406-
if (buf[0] === 0x5b) throw new Error('no arrays')
407-
} })
407+
var server = createServer({
408+
verify: function (req, res, buf) {
409+
if (buf[0] === 0x5b) throw new Error('no arrays')
410+
}
411+
})
408412

409413
request(server)
410414
.post('/')
@@ -415,12 +419,14 @@ describe('bodyParser.json()', function () {
415419
})
416420

417421
it('should allow custom codes', function (done) {
418-
var server = createServer({ verify: function (req, res, buf) {
419-
if (buf[0] !== 0x5b) return
420-
var err = new Error('no arrays')
421-
err.status = 400
422-
throw err
423-
} })
422+
var server = createServer({
423+
verify: function (req, res, buf) {
424+
if (buf[0] !== 0x5b) return
425+
var err = new Error('no arrays')
426+
err.status = 400
427+
throw err
428+
}
429+
})
424430

425431
request(server)
426432
.post('/')
@@ -430,12 +436,14 @@ describe('bodyParser.json()', function () {
430436
})
431437

432438
it('should allow custom type', function (done) {
433-
var server = createServer({ verify: function (req, res, buf) {
434-
if (buf[0] !== 0x5b) return
435-
var err = new Error('no arrays')
436-
err.type = 'foo.bar'
437-
throw err
438-
} })
439+
var server = createServer({
440+
verify: function (req, res, buf) {
441+
if (buf[0] !== 0x5b) return
442+
var err = new Error('no arrays')
443+
err.type = 'foo.bar'
444+
throw err
445+
}
446+
})
439447

440448
request(server)
441449
.post('/')
@@ -446,9 +454,11 @@ describe('bodyParser.json()', function () {
446454
})
447455

448456
it('should include original body on error object', function (done) {
449-
var server = createServer({ verify: function (req, res, buf) {
450-
if (buf[0] === 0x5b) throw new Error('no arrays')
451-
} })
457+
var server = createServer({
458+
verify: function (req, res, buf) {
459+
if (buf[0] === 0x5b) throw new Error('no arrays')
460+
}
461+
})
452462

453463
request(server)
454464
.post('/')
@@ -459,9 +469,11 @@ describe('bodyParser.json()', function () {
459469
})
460470

461471
it('should allow pass-through', function (done) {
462-
var server = createServer({ verify: function (req, res, buf) {
463-
if (buf[0] === 0x5b) throw new Error('no arrays')
464-
} })
472+
var server = createServer({
473+
verify: function (req, res, buf) {
474+
if (buf[0] === 0x5b) throw new Error('no arrays')
475+
}
476+
})
465477

466478
request(server)
467479
.post('/')
@@ -471,9 +483,11 @@ describe('bodyParser.json()', function () {
471483
})
472484

473485
it('should work with different charsets', function (done) {
474-
var server = createServer({ verify: function (req, res, buf) {
475-
if (buf[0] === 0x5b) throw new Error('no arrays')
476-
} })
486+
var server = createServer({
487+
verify: function (req, res, buf) {
488+
if (buf[0] === 0x5b) throw new Error('no arrays')
489+
}
490+
})
477491

478492
var test = request(server).post('/')
479493
test.set('Content-Type', 'application/json; charset=utf-16')
@@ -482,9 +496,11 @@ describe('bodyParser.json()', function () {
482496
})
483497

484498
it('should 415 on unknown charset prior to verify', function (done) {
485-
var server = createServer({ verify: function (req, res, buf) {
486-
throw new Error('unexpected verify call')
487-
} })
499+
var server = createServer({
500+
verify: function (req, res, buf) {
501+
throw new Error('unexpected verify call')
502+
}
503+
})
488504

489505
var test = request(server).post('/')
490506
test.set('Content-Type', 'application/json; charset=x-bogus')

test/raw.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,11 @@ describe('bodyParser.raw()', function () {
248248
})
249249

250250
it('should error from verify', function (done) {
251-
var server = createServer({ verify: function (req, res, buf) {
252-
if (buf[0] === 0x00) throw new Error('no leading null')
253-
} })
251+
var server = createServer({
252+
verify: function (req, res, buf) {
253+
if (buf[0] === 0x00) throw new Error('no leading null')
254+
}
255+
})
254256

255257
var test = request(server).post('/')
256258
test.set('Content-Type', 'application/octet-stream')
@@ -259,12 +261,14 @@ describe('bodyParser.raw()', function () {
259261
})
260262

261263
it('should allow custom codes', function (done) {
262-
var server = createServer({ verify: function (req, res, buf) {
263-
if (buf[0] !== 0x00) return
264-
var err = new Error('no leading null')
265-
err.status = 400
266-
throw err
267-
} })
264+
var server = createServer({
265+
verify: function (req, res, buf) {
266+
if (buf[0] !== 0x00) return
267+
var err = new Error('no leading null')
268+
err.status = 400
269+
throw err
270+
}
271+
})
268272

269273
var test = request(server).post('/')
270274
test.set('Content-Type', 'application/octet-stream')
@@ -273,9 +277,11 @@ describe('bodyParser.raw()', function () {
273277
})
274278

275279
it('should allow pass-through', function (done) {
276-
var server = createServer({ verify: function (req, res, buf) {
277-
if (buf[0] === 0x00) throw new Error('no leading null')
278-
} })
280+
var server = createServer({
281+
verify: function (req, res, buf) {
282+
if (buf[0] === 0x00) throw new Error('no leading null')
283+
}
284+
})
279285

280286
var test = request(server).post('/')
281287
test.set('Content-Type', 'application/octet-stream')

0 commit comments

Comments
 (0)