Skip to content
Myr

deps: body-parser@1.20.0

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent a107702 · Browse files · 6 files+817 added−221 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+817 added−221 removed

  • tests:+806 added−220 removed
  • other:+11 added−1 removed

6 files+817 added−221 removed

modified:test/express.json.js+232 added-107 removed
1'use strict'23var assert = require('assert')4var asyncHooks = tryRequire('async_hooks')5var Buffer = require('safe-buffer').Buffer6var express = require('..')7var request = require('supertest')89var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'10 ? describe11 : describe.skip1213describe('express.json()', function () {14 it('should parse JSON', function (done) {15 request(createApp())16 .post('/')
25 unmodified lines
42 .unset('Transfer-Encoding')43 .expect(200, '{}', done)44 })4546 it('should 400 when only whitespace', function (done) {47 request(createApp())48 .post('/')49 .set('Content-Type', 'application/json')50 .send(' \n')51 .expect(400, '[entity.parse.failed] ' + parseError(' '), done)52 })5354 it('should 400 when invalid content-length', function (done) {55 var app = express()5657 app.use(function (req, res, next) {
13 unmodified lines
71 .send('{"str":')72 .expect(400, /content length/, done)73 })7475 it('should 500 if stream not readable', function (done) {76 var app = express()7778 app.use(function (req, res, next) {79 req.on('end', next)80 req.resume()81 })8283 app.use(express.json())8485 app.use(function (err, req, res, next) {86 res.status(err.status || 500)87 res.send('[' + err.type + '] ' + err.message)88 })8990 app.post('/', function (req, res) {91 res.json(req.body)92 })9394 request(app)95 .post('/')96 .set('Content-Type', 'application/json')97 .send('{"user":"tobi"}')98 .expect(500, '[stream.not.readable] stream is not readable', done)99 })100101 it('should handle duplicated middleware', function (done) {102 var app = express()103104 app.use(express.json())
19 unmodified lines
124 request(this.app)125 .post('/')126 .set('Content-Type', 'application/json')127 .send('{:')89 .expect(400, parseError('{:'), done)128 .expect(400, '[entity.parse.failed] ' + parseError('{:'), done)129 })130131 it('should 400 for incomplete', function (done) {132 request(this.app)133 .post('/')134 .set('Content-Type', 'application/json')135 .send('{"user"')97 .expect(400, parseError('{"user"'), done)136 .expect(400, '[entity.parse.failed] ' + parseError('{"user"'), done)137 })138100 it('should error with type = "entity.parse.failed"', function (done) {101 request(this.app)102 .post('/')103 .set('Content-Type', 'application/json')104 .set('X-Error-Property', 'type')105 .send(' {"user"')106 .expect(400, 'entity.parse.failed', done)107 })108139 it('should include original body on error object', function (done) {140 request(this.app)141 .post('/')142 .set('Content-Type', 'application/json')
10 unmodified lines
153 .post('/')154 .set('Content-Type', 'application/json')155 .set('Content-Length', '1034')156 .send(JSON.stringify({ str: buf.toString() }))127 .expect(413, done)157 .expect(413, '[entity.too.large] request entity too large', done)158 })159130 it('should error with type = "entity.too.large"', function (done) {131 var buf = Buffer.alloc(1024, '.')132 request(createApp({ limit: '1kb' }))133 .post('/')134 .set('Content-Type', 'application/json')135 .set('Content-Length', '1034')136 .set('X-Error-Property', 'type')137 .send(JSON.stringify({ str: buf.toString() }))138 .expect(413, 'entity.too.large', done)139 })140160 it('should 413 when over limit with chunked encoding', function (done) {161 var app = createApp({ limit: '1kb' })162 var buf = Buffer.alloc(1024, '.')143 var server = createApp({ limit: '1kb' })144 var test = request(server).post('/')163 var test = request(app).post('/')164 test.set('Content-Type', 'application/json')165 test.set('Transfer-Encoding', 'chunked')166 test.write('{"str":')167 test.write('"' + buf.toString() + '"}')168 test.expect(413, done)169 })170171 it('should 413 when inflated body over limit', function (done) {172 var app = createApp({ limit: '1kb' })173 var test = request(app).post('/')174 test.set('Content-Encoding', 'gzip')175 test.set('Content-Type', 'application/json')176 test.write(Buffer.from('1f8b080000000000000aab562a2e2952b252d21b05a360148c58a0540b0066f7ce1e0a040000', 'hex'))177 test.expect(413, done)178 })179180 it('should accept number of bytes', function (done) {181 var buf = Buffer.alloc(1024, '.')182 request(createApp({ limit: 1024 }))183 .post('/')
4 unmodified lines
188189 it('should not change when options altered', function (done) {190 var buf = Buffer.alloc(1024, '.')191 var options = { limit: '1kb' }164 var server = createApp(options)192 var app = createApp(options)193194 options.limit = '100kb'195168 request(server)196 request(app)197 .post('/')198 .set('Content-Type', 'application/json')199 .send(JSON.stringify({ str: buf.toString() }))200 .expect(413, done)201 })202203 it('should not hang response', function (done) {204 var buf = Buffer.alloc(10240, '.')177 var server = createApp({ limit: '8kb' })178 var test = request(server).post('/')205 var app = createApp({ limit: '8kb' })206 var test = request(app).post('/')207 test.set('Content-Type', 'application/json')208 test.write(buf)209 test.write(buf)210 test.write(buf)211 test.expect(413, done)212 })213214 it('should not error when inflating', function (done) {215 var app = createApp({ limit: '1kb' })216 var test = request(app).post('/')217 test.set('Content-Encoding', 'gzip')218 test.set('Content-Type', 'application/json')219 test.write(Buffer.from('1f8b080000000000000aab562a2e2952b252d21b05a360148c58a0540b0066f7ce1e0a0400', 'hex'))220 test.expect(413, done)221 })222 })223224 describe('with inflate option', function () {225 describe('when false', function () {
5 unmodified lines
231 var test = request(this.app).post('/')232 test.set('Content-Encoding', 'gzip')233 test.set('Content-Type', 'application/json')234 test.write(Buffer.from('1f8b080000000000000bab56ca4bcc4d55b2527ab16e97522d00515be1cc0e000000', 'hex'))198 test.expect(415, 'content encoding unsupported', done)235 test.expect(415, '[encoding.unsupported] content encoding unsupported', done)236 })237 })238239 describe('when true', function () {
21 unmodified lines
261 request(this.app)262 .post('/')263 .set('Content-Type', 'application/json')264 .send('true')228 .expect(400, parseError('#rue').replace('#', 't'), done)265 .expect(400, '[entity.parse.failed] ' + parseError('#rue').replace('#', 't'), done)266 })267 })268269 describe('when false', function () {
19 unmodified lines
289 request(this.app)290 .post('/')291 .set('Content-Type', 'application/json')292 .send('true')256 .expect(400, parseError('#rue').replace('#', 't'), done)293 .expect(400, '[entity.parse.failed] ' + parseError('#rue').replace('#', 't'), done)294 })295296 it('should not parse primitives with leading whitespaces', function (done) {297 request(this.app)298 .post('/')299 .set('Content-Type', 'application/json')300 .send(' true')264 .expect(400, parseError(' #rue').replace('#', 't'), done)301 .expect(400, '[entity.parse.failed] ' + parseError(' #rue').replace('#', 't'), done)302 })303304 it('should allow leading whitespaces in JSON', function (done) {305 request(this.app)
2 unmodified lines
308 .send(' { "user": "tobi" }')309 .expect(200, '{"user":"tobi"}', done)310 })311275 it('should error with type = "entity.parse.failed"', function (done) {276 request(this.app)277 .post('/')278 .set('Content-Type', 'application/json')279 .set('X-Error-Property', 'type')280 .send('true')281 .expect(400, 'entity.parse.failed', done)282 })283312 it('should include correct message in stack trace', function (done) {313 request(this.app)314 .post('/')315 .set('Content-Type', 'application/json')
108 unmodified lines
424 /TypeError: option verify must be function/)425 })426427 it('should error from verify', function (done) {428 var app = createApp({400 var app = createApp({ verify: function (req, res, buf) {401 if (buf[0] === 0x5b) throw new Error('no arrays')402 } })429 verify: function (req, res, buf) {430 if (buf[0] === 0x5b) throw new Error('no arrays')431 }432 })433434 request(app)435 .post('/')436 .set('Content-Type', 'application/json')437 .send('["tobi"]')408 .expect(403, 'no arrays', done)438 .expect(403, '[entity.verify.failed] no arrays', done)439 })440411 it('should error with type = "entity.verify.failed"', function (done) {412 var app = createApp({ verify: function (req, res, buf) {413 if (buf[0] === 0x5b) throw new Error('no arrays')414 } })415416 request(app)417 .post('/')418 .set('Content-Type', 'application/json')419 .set('X-Error-Property', 'type')420 .send('["tobi"]')421 .expect(403, 'entity.verify.failed', done)422 })423441 it('should allow custom codes', function (done) {442 var app = createApp({425 var app = createApp({ verify: function (req, res, buf) {426 if (buf[0] !== 0x5b) return427 var err = new Error('no arrays')428 err.status = 400429 throw err430 } })443 verify: function (req, res, buf) {444 if (buf[0] !== 0x5b) return445 var err = new Error('no arrays')446 err.status = 400447 throw err448 }449 })450451 request(app)452 .post('/')453 .set('Content-Type', 'application/json')454 .send('["tobi"]')436 .expect(400, 'no arrays', done)455 .expect(400, '[entity.verify.failed] no arrays', done)456 })457458 it('should allow custom type', function (done) {459 var app = createApp({440 var app = createApp({ verify: function (req, res, buf) {441 if (buf[0] !== 0x5b) return442 var err = new Error('no arrays')443 err.type = 'foo.bar'444 throw err445 } })460 verify: function (req, res, buf) {461 if (buf[0] !== 0x5b) return462 var err = new Error('no arrays')463 err.type = 'foo.bar'464 throw err465 }466 })467468 request(app)469 .post('/')470 .set('Content-Type', 'application/json')450 .set('X-Error-Property', 'type')471 .send('["tobi"]')452 .expect(403, 'foo.bar', done)472 .expect(403, '[foo.bar] no arrays', done)473 })474475 it('should include original body on error object', function (done) {476 var app = createApp({456 var app = createApp({ verify: function (req, res, buf) {457 if (buf[0] === 0x5b) throw new Error('no arrays')458 } })477 verify: function (req, res, buf) {478 if (buf[0] === 0x5b) throw new Error('no arrays')479 }480 })481482 request(app)483 .post('/')484 .set('Content-Type', 'application/json')
2 unmodified lines
487 .expect(403, '["tobi"]', done)488 })489490 it('should allow pass-through', function (done) {491 var app = createApp({469 var app = createApp({ verify: function (req, res, buf) {470 if (buf[0] === 0x5b) throw new Error('no arrays')471 } })492 verify: function (req, res, buf) {493 if (buf[0] === 0x5b) throw new Error('no arrays')494 }495 })496497 request(app)498 .post('/')499 .set('Content-Type', 'application/json')
1 unmodified line
501 .expect(200, '{"user":"tobi"}', done)502 })503504 it('should work with different charsets', function (done) {505 var app = createApp({481 var app = createApp({ verify: function (req, res, buf) {482 if (buf[0] === 0x5b) throw new Error('no arrays')483 } })506 verify: function (req, res, buf) {507 if (buf[0] === 0x5b) throw new Error('no arrays')508 }509 })510511 var test = request(app).post('/')512 test.set('Content-Type', 'application/json; charset=utf-16')513 test.write(Buffer.from('feff007b0022006e0061006d00650022003a00228bba0022007d', 'hex'))514 test.expect(200, '{"name":"论"}', done)515 })516517 it('should 415 on unknown charset prior to verify', function (done) {518 var app = createApp({492 var app = createApp({ verify: function (req, res, buf) {493 throw new Error('unexpected verify call')494 } })519 verify: function (req, res, buf) {520 throw new Error('unexpected verify call')521 }522 })523524 var test = request(app).post('/')525 test.set('Content-Type', 'application/json; charset=x-bogus')526 test.write(Buffer.from('00000000', 'hex'))499 test.expect(415, 'unsupported charset "X-BOGUS"', done)527 test.expect(415, '[charset.unsupported] unsupported charset "X-BOGUS"', done)528 })529 })530531 describeAsyncHooks('async local storage', function () {532 before(function () {533 var app = express()534 var store = { foo: 'bar' }535536 app.use(function (req, res, next) {537 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()538 req.asyncLocalStorage.run(store, next)539 })540541 app.use(express.json())542543 app.use(function (req, res, next) {544 var local = req.asyncLocalStorage.getStore()545546 if (local) {547 res.setHeader('x-store-foo', String(local.foo))548 }549550 next()551 })552553 app.use(function (err, req, res, next) {554 var local = req.asyncLocalStorage.getStore()555556 if (local) {557 res.setHeader('x-store-foo', String(local.foo))558 }559560 res.status(err.status || 500)561 res.send('[' + err.type + '] ' + err.message)562 })563564 app.post('/', function (req, res) {565 res.json(req.body)566 })567568 this.app = app569 })570571 it('should presist store', function (done) {572 request(this.app)573 .post('/')574 .set('Content-Type', 'application/json')575 .send('{"user":"tobi"}')576 .expect(200)577 .expect('x-store-foo', 'bar')578 .expect('{"user":"tobi"}')579 .end(done)580 })581582 it('should presist store when unmatched content-type', function (done) {583 request(this.app)584 .post('/')585 .set('Content-Type', 'application/fizzbuzz')586 .send('buzz')587 .expect(200)588 .expect('x-store-foo', 'bar')589 .expect('{}')590 .end(done)591 })592593 it('should presist store when inflated', function (done) {594 var test = request(this.app).post('/')595 test.set('Content-Encoding', 'gzip')596 test.set('Content-Type', 'application/json')597 test.write(Buffer.from('1f8b080000000000000bab56ca4bcc4d55b2527ab16e97522d00515be1cc0e000000', 'hex'))598 test.expect(200)599 test.expect('x-store-foo', 'bar')600 test.expect('{"name":"论"}')601 test.end(done)602 })603604 it('should presist store when inflate error', function (done) {605 var test = request(this.app).post('/')606 test.set('Content-Encoding', 'gzip')607 test.set('Content-Type', 'application/json')608 test.write(Buffer.from('1f8b080000000000000bab56cc4d55b2527ab16e97522d00515be1cc0e000000', 'hex'))609 test.expect(400)610 test.expect('x-store-foo', 'bar')611 test.end(done)612 })613614 it('should presist store when parse error', function (done) {615 request(this.app)616 .post('/')617 .set('Content-Type', 'application/json')618 .send('{"user":')619 .expect(400)620 .expect('x-store-foo', 'bar')621 .end(done)622 })623624 it('should presist store when limit exceeded', function (done) {625 request(this.app)626 .post('/')627 .set('Content-Type', 'application/json')628 .send('{"user":"' + Buffer.alloc(1024 * 100, '.').toString() + '"}')629 .expect(413)630 .expect('x-store-foo', 'bar')631 .end(done)632 })633 })634635 describe('charset', function () {636 before(function () {637 this.app = createApp()638 })
30 unmodified lines
669 it('should fail on unknown charset', function (done) {670 var test = request(this.app).post('/')671 test.set('Content-Type', 'application/json; charset=koi8-r')672 test.write(Buffer.from('7b226e616d65223a22cec5d4227d', 'hex'))541 test.expect(415, 'unsupported charset "KOI8-R"', done)673 test.expect(415, '[charset.unsupported] unsupported charset "KOI8-R"', done)674 })543544 it('should error with type = "charset.unsupported"', function (done) {545 var test = request(this.app).post('/')546 test.set('Content-Type', 'application/json; charset=koi8-r')547 test.set('X-Error-Property', 'type')548 test.write(Buffer.from('7b226e616d65223a22cec5d4227d', 'hex'))549 test.expect(415, 'charset.unsupported', done)550 })675 })676677 describe('encoding', function () {678 before(function () {
43 unmodified lines
722 var test = request(this.app).post('/')723 test.set('Content-Encoding', 'nulls')724 test.set('Content-Type', 'application/json')725 test.write(Buffer.from('000000000000', 'hex'))602 test.expect(415, 'unsupported content encoding "nulls"', done)726 test.expect(415, '[encoding.unsupported] unsupported content encoding "nulls"', done)727 })728605 it('should error with type = "encoding.unsupported"', function (done) {606 var test = request(this.app).post('/')607 test.set('Content-Encoding', 'nulls')608 test.set('Content-Type', 'application/json')609 test.set('X-Error-Property', 'type')610 test.write(Buffer.from('000000000000', 'hex'))611 test.expect(415, 'encoding.unsupported', done)612 })613729 it('should 400 on malformed encoding', function (done) {730 var test = request(this.app).post('/')731 test.set('Content-Encoding', 'gzip')732 test.set('Content-Type', 'application/json')
20 unmodified lines
753 app.use(express.json(options))754755 app.use(function (err, req, res, next) {756 res.status(err.status || 500)642 res.send(String(err[req.headers['x-error-property'] || 'message']))757 res.send(String(req.headers['x-error-property']758 ? err[req.headers['x-error-property']]759 : ('[' + err.type + '] ' + err.message)))760 })761762 app.post('/', function (req, res) {763 res.json(req.body)
15 unmodified lines
779 assert.ok(res.text.indexOf(str) !== -1,780 'expected \'' + res.text + '\' to contain \'' + str + '\'')781 }782}783784function tryRequire (name) {785 try {786 return require(name)787 } catch (e) {788 return {}789 }790}
modified:test/express.raw.js+185 added-18 removed
1'use strict'23var assert = require('assert')4var asyncHooks = tryRequire('async_hooks')5var Buffer = require('safe-buffer').Buffer6var express = require('..')7var request = require('supertest')89var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'10 ? describe11 : describe.skip1213describe('express.raw()', function () {14 before(function () {15 this.app = createApp()16 })
47 unmodified lines
64 .send('')65 .expect(200, { buf: '' }, done)66 })6768 it('should 500 if stream not readable', function (done) {69 var app = express()7071 app.use(function (req, res, next) {72 req.on('end', next)73 req.resume()74 })7576 app.use(express.raw())7778 app.use(function (err, req, res, next) {79 res.status(err.status || 500)80 res.send('[' + err.type + '] ' + err.message)81 })8283 app.post('/', function (req, res) {84 if (Buffer.isBuffer(req.body)) {85 res.json({ buf: req.body.toString('hex') })86 } else {87 res.json(req.body)88 }89 })9091 request(app)92 .post('/')93 .set('Content-Type', 'application/octet-stream')94 .send('the user is tobi')95 .expect(500, '[stream.not.readable] stream is not readable', done)96 })9798 it('should handle duplicated middleware', function (done) {99 var app = express()100101 app.use(express.raw())
34 unmodified lines
136 test.write(buf)137 test.expect(413, done)138 })139140 it('should 413 when inflated body over limit', function (done) {141 var app = createApp({ limit: '1kb' })142 var test = request(app).post('/')143 test.set('Content-Encoding', 'gzip')144 test.set('Content-Type', 'application/octet-stream')145 test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a14704040000', 'hex'))146 test.expect(413, done)147 })148149 it('should accept number of bytes', function (done) {150 var buf = Buffer.alloc(1028, '.')151 var app = createApp({ limit: 1024 })152 var test = request(app).post('/')
24 unmodified lines
177 test.write(buf)178 test.write(buf)179 test.expect(413, done)180 })181182 it('should not error when inflating', function (done) {183 var app = createApp({ limit: '1kb' })184 var test = request(app).post('/')185 test.set('Content-Encoding', 'gzip')186 test.set('Content-Type', 'application/octet-stream')187 test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a147040400', 'hex'))188 test.expect(413, done)189 })190 })191192 describe('with inflate option', function () {193 describe('when false', function () {
5 unmodified lines
199 var test = request(this.app).post('/')200 test.set('Content-Encoding', 'gzip')201 test.set('Content-Type', 'application/octet-stream')202 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))150 test.expect(415, 'content encoding unsupported', done)203 test.expect(415, '[encoding.unsupported] content encoding unsupported', done)204 })205 })206207 describe('when true', function () {
107 unmodified lines
315 /TypeError: option verify must be function/)316 })317318 it('should error from verify', function (done) {319 var app = createApp({266 var app = createApp({ verify: function (req, res, buf) {267 if (buf[0] === 0x00) throw new Error('no leading null')268 } })320 verify: function (req, res, buf) {321 if (buf[0] === 0x00) throw new Error('no leading null')322 }323 })324325 var test = request(app).post('/')326 test.set('Content-Type', 'application/octet-stream')327 test.write(Buffer.from('000102', 'hex'))273 test.expect(403, 'no leading null', done)328 test.expect(403, '[entity.verify.failed] no leading null', done)329 })330331 it('should allow custom codes', function (done) {332 var app = createApp({277 var app = createApp({ verify: function (req, res, buf) {278 if (buf[0] !== 0x00) return279 var err = new Error('no leading null')280 err.status = 400281 throw err282 } })333 verify: function (req, res, buf) {334 if (buf[0] !== 0x00) return335 var err = new Error('no leading null')336 err.status = 400337 throw err338 }339 })340341 var test = request(app).post('/')342 test.set('Content-Type', 'application/octet-stream')343 test.write(Buffer.from('000102', 'hex'))287 test.expect(400, 'no leading null', done)344 test.expect(400, '[entity.verify.failed] no leading null', done)345 })346347 it('should allow pass-through', function (done) {348 var app = createApp({291 var app = createApp({ verify: function (req, res, buf) {292 if (buf[0] === 0x00) throw new Error('no leading null')293 } })349 verify: function (req, res, buf) {350 if (buf[0] === 0x00) throw new Error('no leading null')351 }352 })353354 var test = request(app).post('/')355 test.set('Content-Type', 'application/octet-stream')356 test.write(Buffer.from('0102', 'hex'))357 test.expect(200, { buf: '0102' }, done)358 })359 })360361 describeAsyncHooks('async local storage', function () {362 before(function () {363 var app = express()364 var store = { foo: 'bar' }365366 app.use(function (req, res, next) {367 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()368 req.asyncLocalStorage.run(store, next)369 })370371 app.use(express.raw())372373 app.use(function (req, res, next) {374 var local = req.asyncLocalStorage.getStore()375376 if (local) {377 res.setHeader('x-store-foo', String(local.foo))378 }379380 next()381 })382383 app.use(function (err, req, res, next) {384 var local = req.asyncLocalStorage.getStore()385386 if (local) {387 res.setHeader('x-store-foo', String(local.foo))388 }389390 res.status(err.status || 500)391 res.send('[' + err.type + '] ' + err.message)392 })393394 app.post('/', function (req, res) {395 if (Buffer.isBuffer(req.body)) {396 res.json({ buf: req.body.toString('hex') })397 } else {398 res.json(req.body)399 }400 })401402 this.app = app403 })404405 it('should presist store', function (done) {406 request(this.app)407 .post('/')408 .set('Content-Type', 'application/octet-stream')409 .send('the user is tobi')410 .expect(200)411 .expect('x-store-foo', 'bar')412 .expect({ buf: '746865207573657220697320746f6269' })413 .end(done)414 })415416 it('should presist store when unmatched content-type', function (done) {417 request(this.app)418 .post('/')419 .set('Content-Type', 'application/fizzbuzz')420 .send('buzz')421 .expect(200)422 .expect('x-store-foo', 'bar')423 .expect('{}')424 .end(done)425 })426427 it('should presist store when inflated', function (done) {428 var test = request(this.app).post('/')429 test.set('Content-Encoding', 'gzip')430 test.set('Content-Type', 'application/octet-stream')431 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))432 test.expect(200)433 test.expect('x-store-foo', 'bar')434 test.expect({ buf: '6e616d653de8aeba' })435 test.end(done)436 })437438 it('should presist store when inflate error', function (done) {439 var test = request(this.app).post('/')440 test.set('Content-Encoding', 'gzip')441 test.set('Content-Type', 'application/octet-stream')442 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad6080000', 'hex'))443 test.expect(400)444 test.expect('x-store-foo', 'bar')445 test.end(done)446 })447448 it('should presist store when limit exceeded', function (done) {449 request(this.app)450 .post('/')451 .set('Content-Type', 'application/octet-stream')452 .send('the user is ' + Buffer.alloc(1024 * 100, '.').toString())453 .expect(413)454 .expect('x-store-foo', 'bar')455 .end(done)456 })457 })458459 describe('charset', function () {460 before(function () {461 this.app = createApp()462 })
49 unmodified lines
512 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))513 test.expect(200, { buf: '6e616d653de8aeba' }, done)514 })515359 it('should fail on unknown encoding', function (done) {516 it('should 415 on unknown encoding', function (done) {517 var test = request(this.app).post('/')518 test.set('Content-Encoding', 'nulls')519 test.set('Content-Type', 'application/octet-stream')520 test.write(Buffer.from('000000000000', 'hex'))364 test.expect(415, 'unsupported content encoding "nulls"', done)521 test.expect(415, '[encoding.unsupported] unsupported content encoding "nulls"', done)522 })523 })524})525
3 unmodified lines
529 app.use(express.raw(options))530531 app.use(function (err, req, res, next) {532 res.status(err.status || 500)376 res.send(String(err[req.headers['x-error-property'] || 'message']))533 res.send(String(req.headers['x-error-property']534 ? err[req.headers['x-error-property']]535 : ('[' + err.type + '] ' + err.message)))536 })537538 app.post('/', function (req, res) {539 if (Buffer.isBuffer(req.body)) {
4 unmodified lines
544 })545546 return app547}548549function tryRequire (name) {550 try {551 return require(name)552 } catch (e) {553 return {}554 }555}
modified:test/express.text.js+192 added-29 removed
1'use strict'23var assert = require('assert')4var asyncHooks = tryRequire('async_hooks')5var Buffer = require('safe-buffer').Buffer6var express = require('..')7var request = require('supertest')89var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'10 ? describe11 : describe.skip1213describe('express.text()', function () {14 before(function () {15 this.app = createApp()16 })
43 unmodified lines
60 .send('')61 .expect(200, '""', done)62 })6364 it('should 500 if stream not readable', function (done) {65 var app = express()6667 app.use(function (req, res, next) {68 req.on('end', next)69 req.resume()70 })7172 app.use(express.text())7374 app.use(function (err, req, res, next) {75 res.status(err.status || 500)76 res.send('[' + err.type + '] ' + err.message)77 })7879 app.post('/', function (req, res) {80 res.json(req.body)81 })8283 request(app)84 .post('/')85 .set('Content-Type', 'text/plain')86 .send('user is tobi')87 .expect(500, '[stream.not.readable] stream is not readable', done)88 })8990 it('should handle duplicated middleware', function (done) {91 var app = express()9293 app.use(express.text())
11 unmodified lines
105 })106107 describe('with defaultCharset option', function () {108 it('should change default charset', function (done) {78 var app = createApp({ defaultCharset: 'koi8-r' })79 var test = request(app).post('/')109 var server = createApp({ defaultCharset: 'koi8-r' })110 var test = request(server).post('/')111 test.set('Content-Type', 'text/plain')112 test.write(Buffer.from('6e616d6520697320cec5d4', 'hex'))113 test.expect(200, '"name is нет"', done)114 })115116 it('should honor content-type charset', function (done) {86 var app = createApp({ defaultCharset: 'koi8-r' })87 var test = request(app).post('/')117 var server = createApp({ defaultCharset: 'koi8-r' })118 var test = request(server).post('/')119 test.set('Content-Type', 'text/plain; charset=utf-8')120 test.write(Buffer.from('6e616d6520697320e8aeba', 'hex'))121 test.expect(200, '"name is 论"', done)122 })
10 unmodified lines
133 .expect(413, done)134 })135136 it('should 413 when over limit with chunked encoding', function (done) {106 var buf = Buffer.alloc(1028, '.')137 var app = createApp({ limit: '1kb' })138 var buf = Buffer.alloc(1028, '.')139 var test = request(app).post('/')140 test.set('Content-Type', 'text/plain')141 test.set('Transfer-Encoding', 'chunked')142 test.write(buf.toString())143 test.expect(413, done)144 })145146 it('should 413 when inflated body over limit', function (done) {147 var app = createApp({ limit: '1kb' })148 var test = request(app).post('/')149 test.set('Content-Encoding', 'gzip')150 test.set('Content-Type', 'text/plain')151 test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a14704040000', 'hex'))152 test.expect(413, done)153 })154155 it('should accept number of bytes', function (done) {156 var buf = Buffer.alloc(1028, '.')157 request(createApp({ limit: 1024 }))158 .post('/')
16 unmodified lines
175 .expect(413, done)176 })177178 it('should not hang response', function (done) {139 var buf = Buffer.alloc(10240, '.')179 var app = createApp({ limit: '8kb' })180 var buf = Buffer.alloc(10240, '.')181 var test = request(app).post('/')182 test.set('Content-Type', 'text/plain')183 test.write(buf)184 test.write(buf)185 test.write(buf)186 test.expect(413, done)187 })188189 it('should not error when inflating', function (done) {190 var app = createApp({ limit: '1kb' })191 var test = request(app).post('/')192 test.set('Content-Encoding', 'gzip')193 test.set('Content-Type', 'text/plain')194 test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a1470404', 'hex'))195 setTimeout(function () {196 test.expect(413, done)197 }, 100)198 })199 })200201 describe('with inflate option', function () {202 describe('when false', function () {
5 unmodified lines
208 var test = request(this.app).post('/')209 test.set('Content-Encoding', 'gzip')210 test.set('Content-Type', 'text/plain')211 test.write(Buffer.from('1f8b080000000000000bcb4bcc4d55c82c5678b16e170072b3e0200b000000', 'hex'))161 test.expect(415, 'content encoding unsupported', done)212 test.expect(415, '[encoding.unsupported] content encoding unsupported', done)213 })214 })215216 describe('when true', function () {
111 unmodified lines
328 /TypeError: option verify must be function/)329 })330331 it('should error from verify', function (done) {332 var app = createApp({281 var app = createApp({ verify: function (req, res, buf) {282 if (buf[0] === 0x20) throw new Error('no leading space')283 } })333 verify: function (req, res, buf) {334 if (buf[0] === 0x20) throw new Error('no leading space')335 }336 })337338 request(app)339 .post('/')340 .set('Content-Type', 'text/plain')341 .send(' user is tobi')289 .expect(403, 'no leading space', done)342 .expect(403, '[entity.verify.failed] no leading space', done)343 })344345 it('should allow custom codes', function (done) {346 var app = createApp({293 var app = createApp({ verify: function (req, res, buf) {294 if (buf[0] !== 0x20) return295 var err = new Error('no leading space')296 err.status = 400297 throw err298 } })347 verify: function (req, res, buf) {348 if (buf[0] !== 0x20) return349 var err = new Error('no leading space')350 err.status = 400351 throw err352 }353 })354355 request(app)356 .post('/')357 .set('Content-Type', 'text/plain')358 .send(' user is tobi')304 .expect(400, 'no leading space', done)359 .expect(400, '[entity.verify.failed] no leading space', done)360 })361362 it('should allow pass-through', function (done) {363 var app = createApp({308 var app = createApp({ verify: function (req, res, buf) {309 if (buf[0] === 0x20) throw new Error('no leading space')310 } })364 verify: function (req, res, buf) {365 if (buf[0] === 0x20) throw new Error('no leading space')366 }367 })368369 request(app)370 .post('/')371 .set('Content-Type', 'text/plain')
1 unmodified line
373 .expect(200, '"user is tobi"', done)374 })375376 it('should 415 on unknown charset prior to verify', function (done) {377 var app = createApp({320 var app = createApp({ verify: function (req, res, buf) {321 throw new Error('unexpected verify call')322 } })378 verify: function (req, res, buf) {379 throw new Error('unexpected verify call')380 }381 })382383 var test = request(app).post('/')384 test.set('Content-Type', 'text/plain; charset=x-bogus')385 test.write(Buffer.from('00000000', 'hex'))327 test.expect(415, 'unsupported charset "X-BOGUS"', done)386 test.expect(415, '[charset.unsupported] unsupported charset "X-BOGUS"', done)387 })388 })389390 describeAsyncHooks('async local storage', function () {391 before(function () {392 var app = express()393 var store = { foo: 'bar' }394395 app.use(function (req, res, next) {396 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()397 req.asyncLocalStorage.run(store, next)398 })399400 app.use(express.text())401402 app.use(function (req, res, next) {403 var local = req.asyncLocalStorage.getStore()404405 if (local) {406 res.setHeader('x-store-foo', String(local.foo))407 }408409 next()410 })411412 app.use(function (err, req, res, next) {413 var local = req.asyncLocalStorage.getStore()414415 if (local) {416 res.setHeader('x-store-foo', String(local.foo))417 }418419 res.status(err.status || 500)420 res.send('[' + err.type + '] ' + err.message)421 })422423 app.post('/', function (req, res) {424 res.json(req.body)425 })426427 this.app = app428 })429430 it('should presist store', function (done) {431 request(this.app)432 .post('/')433 .set('Content-Type', 'text/plain')434 .send('user is tobi')435 .expect(200)436 .expect('x-store-foo', 'bar')437 .expect('"user is tobi"')438 .end(done)439 })440441 it('should presist store when unmatched content-type', function (done) {442 request(this.app)443 .post('/')444 .set('Content-Type', 'application/fizzbuzz')445 .send('buzz')446 .expect(200)447 .expect('x-store-foo', 'bar')448 .expect('{}')449 .end(done)450 })451452 it('should presist store when inflated', function (done) {453 var test = request(this.app).post('/')454 test.set('Content-Encoding', 'gzip')455 test.set('Content-Type', 'text/plain')456 test.write(Buffer.from('1f8b080000000000000bcb4bcc4d55c82c5678b16e170072b3e0200b000000', 'hex'))457 test.expect(200)458 test.expect('x-store-foo', 'bar')459 test.expect('"name is 论"')460 test.end(done)461 })462463 it('should presist store when inflate error', function (done) {464 var test = request(this.app).post('/')465 test.set('Content-Encoding', 'gzip')466 test.set('Content-Type', 'text/plain')467 test.write(Buffer.from('1f8b080000000000000bcb4bcc4d55c82c5678b16e170072b3e0200b0000', 'hex'))468 test.expect(400)469 test.expect('x-store-foo', 'bar')470 test.end(done)471 })472473 it('should presist store when limit exceeded', function (done) {474 request(this.app)475 .post('/')476 .set('Content-Type', 'text/plain')477 .send('user is ' + Buffer.alloc(1024 * 100, '.').toString())478 .expect(413)479 .expect('x-store-foo', 'bar')480 .end(done)481 })482 })483484 describe('charset', function () {485 before(function () {486 this.app = createApp()487 })
30 unmodified lines
518 it('should 415 on unknown charset', function (done) {519 var test = request(this.app).post('/')520 test.set('Content-Type', 'text/plain; charset=x-bogus')521 test.write(Buffer.from('00000000', 'hex'))369 test.expect(415, 'unsupported charset "X-BOGUS"', done)522 test.expect(415, '[charset.unsupported] unsupported charset "X-BOGUS"', done)523 })524 })525526 describe('encoding', function () {
39 unmodified lines
566 test.write(Buffer.from('1f8b080000000000000bcb4bcc4d55c82c5678b16e170072b3e0200b000000', 'hex'))567 test.expect(200, '"name is 论"', done)568 })569417 it('should fail on unknown encoding', function (done) {570 it('should 415 on unknown encoding', function (done) {571 var test = request(this.app).post('/')572 test.set('Content-Encoding', 'nulls')573 test.set('Content-Type', 'text/plain')574 test.write(Buffer.from('000000000000', 'hex'))422 test.expect(415, 'unsupported content encoding "nulls"', done)575 test.expect(415, '[encoding.unsupported] unsupported content encoding "nulls"', done)576 })577 })578})579
3 unmodified lines
583 app.use(express.text(options))584585 app.use(function (err, req, res, next) {586 res.status(err.status || 500)434 res.send(err.message)587 res.send(String(req.headers['x-error-property']588 ? err[req.headers['x-error-property']]589 : ('[' + err.type + '] ' + err.message)))590 })591592 app.post('/', function (req, res) {593 res.json(req.body)594 })595596 return app597}598599function tryRequire (name) {600 try {601 return require(name)602 } catch (e) {603 return {}604 }605}
modified:test/express.urlencoded.js+197 added-66 removed
1'use strict'23var assert = require('assert')4var asyncHooks = tryRequire('async_hooks')5var Buffer = require('safe-buffer').Buffer6var express = require('..')7var request = require('supertest')89var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'10 ? describe11 : describe.skip1213describe('express.urlencoded()', function () {14 before(function () {15 this.app = createApp()16 })
44 unmodified lines
61 .send('')62 .expect(200, '{}', done)63 })6465 it('should 500 if stream not readable', function (done) {66 var app = express()6768 app.use(function (req, res, next) {69 req.on('end', next)70 req.resume()71 })7273 app.use(express.urlencoded())7475 app.use(function (err, req, res, next) {76 res.status(err.status || 500)77 res.send('[' + err.type + '] ' + err.message)78 })7980 app.post('/', function (req, res) {81 res.json(req.body)82 })8384 request(app)85 .post('/')86 .set('Content-Type', 'application/x-www-form-urlencoded')87 .send('user=tobi')88 .expect(500, '[stream.not.readable] stream is not readable', done)89 })9091 it('should handle duplicated middleware', function (done) {92 var app = express()9394 app.use(express.urlencoded())
152 unmodified lines
247 var test = request(this.app).post('/')248 test.set('Content-Encoding', 'gzip')249 test.set('Content-Type', 'application/x-www-form-urlencoded')250 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))220 test.expect(415, 'content encoding unsupported', done)251 test.expect(415, '[encoding.unsupported] content encoding unsupported', done)252 })253 })254255 describe('when true', function () {
22 unmodified lines
278 .expect(413, done)279 })280281 it('should 413 when over limit with chunked encoding', function (done) {251 var buf = Buffer.alloc(1024, '.')282 var app = createApp({ limit: '1kb' })283 var buf = Buffer.alloc(1024, '.')284 var test = request(app).post('/')285 test.set('Content-Type', 'application/x-www-form-urlencoded')286 test.set('Transfer-Encoding', 'chunked')287 test.write('str=')288 test.write(buf.toString())289 test.expect(413, done)290 })291292 it('should 413 when inflated body over limit', function (done) {293 var app = createApp({ limit: '1kb' })294 var test = request(app).post('/')295 test.set('Content-Encoding', 'gzip')296 test.set('Content-Type', 'application/x-www-form-urlencoded')297 test.write(Buffer.from('1f8b080000000000000a2b2e29b2d51b05a360148c580000a0351f9204040000', 'hex'))298 test.expect(413, done)299 })300301 it('should accept number of bytes', function (done) {302 var buf = Buffer.alloc(1024, '.')303 request(createApp({ limit: 1024 }))304 .post('/')
16 unmodified lines
321 .expect(413, done)322 })323324 it('should not hang response', function (done) {285 var buf = Buffer.alloc(10240, '.')325 var app = createApp({ limit: '8kb' })326 var buf = Buffer.alloc(10240, '.')327 var test = request(app).post('/')328 test.set('Content-Type', 'application/x-www-form-urlencoded')329 test.write(buf)330 test.write(buf)331 test.write(buf)332 test.expect(413, done)333 })334335 it('should not error when inflating', function (done) {336 var app = createApp({ limit: '1kb' })337 var test = request(app).post('/')338 test.set('Content-Encoding', 'gzip')339 test.set('Content-Type', 'application/x-www-form-urlencoded')340 test.write(Buffer.from('1f8b080000000000000a2b2e29b2d51b05a360148c580000a0351f92040400', 'hex'))341 test.expect(413, done)342 })343 })344345 describe('with parameterLimit option', function () {346 describe('with extended: false', function () {
11 unmodified lines
358 request(createApp({ extended: false, parameterLimit: 10 }))359 .post('/')360 .set('Content-Type', 'application/x-www-form-urlencoded')361 .send(createManyParams(11))313 .expect(413, /too many parameters/, done)362 .expect(413, '[parameters.too.many] too many parameters', done)363 })364316 it('should error with type = "parameters.too.many"', function (done) {317 request(createApp({ extended: false, parameterLimit: 10 }))318 .post('/')319 .set('Content-Type', 'application/x-www-form-urlencoded')320 .set('X-Error-Property', 'type')321 .send(createManyParams(11))322 .expect(413, 'parameters.too.many', done)323 })324365 it('should work when at the limit', function (done) {366 request(createApp({ extended: false, parameterLimit: 10 }))367 .post('/')368 .set('Content-Type', 'application/x-www-form-urlencoded')
44 unmodified lines
413 request(createApp({ extended: true, parameterLimit: 10 }))414 .post('/')415 .set('Content-Type', 'application/x-www-form-urlencoded')416 .send(createManyParams(11))377 .expect(413, /too many parameters/, done)417 .expect(413, '[parameters.too.many] too many parameters', done)418 })419380 it('should error with type = "parameters.too.many"', function (done) {381 request(createApp({ extended: true, parameterLimit: 10 }))382 .post('/')383 .set('Content-Type', 'application/x-www-form-urlencoded')384 .set('X-Error-Property', 'type')385 .send(createManyParams(11))386 .expect(413, 'parameters.too.many', done)387 })388420 it('should work when at the limit', function (done) {421 request(createApp({ extended: true, parameterLimit: 10 }))422 .post('/')423 .set('Content-Type', 'application/x-www-form-urlencoded')
132 unmodified lines
556 /TypeError: option verify must be function/)557 })558559 it('should error from verify', function (done) {560 var app = createApp({529 var app = createApp({ verify: function (req, res, buf) {530 if (buf[0] === 0x20) throw new Error('no leading space')531 } })561 verify: function (req, res, buf) {562 if (buf[0] === 0x20) throw new Error('no leading space')563 }564 })565566 request(app)567 .post('/')568 .set('Content-Type', 'application/x-www-form-urlencoded')569 .send(' user=tobi')537 .expect(403, 'no leading space', done)570 .expect(403, '[entity.verify.failed] no leading space', done)571 })572540 it('should error with type = "entity.verify.failed"', function (done) {541 var app = createApp({ verify: function (req, res, buf) {542 if (buf[0] === 0x20) throw new Error('no leading space')543 } })544545 request(app)546 .post('/')547 .set('Content-Type', 'application/x-www-form-urlencoded')548 .set('X-Error-Property', 'type')549 .send(' user=tobi')550 .expect(403, 'entity.verify.failed', done)551 })552573 it('should allow custom codes', function (done) {574 var app = createApp({554 var app = createApp({ verify: function (req, res, buf) {555 if (buf[0] !== 0x20) return556 var err = new Error('no leading space')557 err.status = 400558 throw err559 } })575 verify: function (req, res, buf) {576 if (buf[0] !== 0x20) return577 var err = new Error('no leading space')578 err.status = 400579 throw err580 }581 })582583 request(app)584 .post('/')585 .set('Content-Type', 'application/x-www-form-urlencoded')586 .send(' user=tobi')565 .expect(400, 'no leading space', done)587 .expect(400, '[entity.verify.failed] no leading space', done)588 })589590 it('should allow custom type', function (done) {591 var app = createApp({569 var app = createApp({ verify: function (req, res, buf) {570 if (buf[0] !== 0x20) return571 var err = new Error('no leading space')572 err.type = 'foo.bar'573 throw err574 } })592 verify: function (req, res, buf) {593 if (buf[0] !== 0x20) return594 var err = new Error('no leading space')595 err.type = 'foo.bar'596 throw err597 }598 })599600 request(app)601 .post('/')602 .set('Content-Type', 'application/x-www-form-urlencoded')579 .set('X-Error-Property', 'type')603 .send(' user=tobi')581 .expect(403, 'foo.bar', done)604 .expect(403, '[foo.bar] no leading space', done)605 })606607 it('should allow pass-through', function (done) {608 var app = createApp({585 var app = createApp({ verify: function (req, res, buf) {586 if (buf[0] === 0x5b) throw new Error('no arrays')587 } })609 verify: function (req, res, buf) {610 if (buf[0] === 0x5b) throw new Error('no arrays')611 }612 })613614 request(app)615 .post('/')616 .set('Content-Type', 'application/x-www-form-urlencoded')
1 unmodified line
618 .expect(200, '{"user":"tobi"}', done)619 })620621 it('should 415 on unknown charset prior to verify', function (done) {622 var app = createApp({597 var app = createApp({ verify: function (req, res, buf) {598 throw new Error('unexpected verify call')599 } })623 verify: function (req, res, buf) {624 throw new Error('unexpected verify call')625 }626 })627628 var test = request(app).post('/')629 test.set('Content-Type', 'application/x-www-form-urlencoded; charset=x-bogus')630 test.write(Buffer.from('00000000', 'hex'))604 test.expect(415, 'unsupported charset "X-BOGUS"', done)631 test.expect(415, '[charset.unsupported] unsupported charset "X-BOGUS"', done)632 })633 })634635 describeAsyncHooks('async local storage', function () {636 before(function () {637 var app = express()638 var store = { foo: 'bar' }639640 app.use(function (req, res, next) {641 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()642 req.asyncLocalStorage.run(store, next)643 })644645 app.use(express.urlencoded())646647 app.use(function (req, res, next) {648 var local = req.asyncLocalStorage.getStore()649650 if (local) {651 res.setHeader('x-store-foo', String(local.foo))652 }653654 next()655 })656657 app.use(function (err, req, res, next) {658 var local = req.asyncLocalStorage.getStore()659660 if (local) {661 res.setHeader('x-store-foo', String(local.foo))662 }663664 res.status(err.status || 500)665 res.send('[' + err.type + '] ' + err.message)666 })667668 app.post('/', function (req, res) {669 res.json(req.body)670 })671672 this.app = app673 })674675 it('should presist store', function (done) {676 request(this.app)677 .post('/')678 .set('Content-Type', 'application/x-www-form-urlencoded')679 .send('user=tobi')680 .expect(200)681 .expect('x-store-foo', 'bar')682 .expect('{"user":"tobi"}')683 .end(done)684 })685686 it('should presist store when unmatched content-type', function (done) {687 request(this.app)688 .post('/')689 .set('Content-Type', 'application/fizzbuzz')690 .send('buzz')691 .expect(200)692 .expect('x-store-foo', 'bar')693 .expect('{}')694 .end(done)695 })696697 it('should presist store when inflated', function (done) {698 var test = request(this.app).post('/')699 test.set('Content-Encoding', 'gzip')700 test.set('Content-Type', 'application/x-www-form-urlencoded')701 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))702 test.expect(200)703 test.expect('x-store-foo', 'bar')704 test.expect('{"name":"论"}')705 test.end(done)706 })707708 it('should presist store when inflate error', function (done) {709 var test = request(this.app).post('/')710 test.set('Content-Encoding', 'gzip')711 test.set('Content-Type', 'application/x-www-form-urlencoded')712 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad6080000', 'hex'))713 test.expect(400)714 test.expect('x-store-foo', 'bar')715 test.end(done)716 })717718 it('should presist store when limit exceeded', function (done) {719 request(this.app)720 .post('/')721 .set('Content-Type', 'application/x-www-form-urlencoded')722 .send('user=' + Buffer.alloc(1024 * 100, '.').toString())723 .expect(413)724 .expect('x-store-foo', 'bar')725 .end(done)726 })727 })728729 describe('charset', function () {730 before(function () {731 this.app = createApp()732 })
23 unmodified lines
756 it('should fail on unknown charset', function (done) {757 var test = request(this.app).post('/')758 test.set('Content-Type', 'application/x-www-form-urlencoded; charset=koi8-r')759 test.write(Buffer.from('6e616d653dcec5d4', 'hex'))639 test.expect(415, 'unsupported charset "KOI8-R"', done)760 test.expect(415, '[charset.unsupported] unsupported charset "KOI8-R"', done)761 })762 })763764 describe('encoding', function () {
39 unmodified lines
804 test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))805 test.expect(200, '{"name":"论"}', done)806 })807687 it('should fail on unknown encoding', function (done) {808 it('should 415 on unknown encoding', function (done) {809 var test = request(this.app).post('/')810 test.set('Content-Encoding', 'nulls')811 test.set('Content-Type', 'application/x-www-form-urlencoded')812 test.write(Buffer.from('000000000000', 'hex'))692 test.expect(415, 'unsupported content encoding "nulls"', done)813 test.expect(415, '[encoding.unsupported] unsupported content encoding "nulls"', done)814 })815 })816})817
20 unmodified lines
838 app.use(express.urlencoded(options))839840 app.use(function (err, req, res, next) {841 res.status(err.status || 500)721 res.send(String(err[req.headers['x-error-property'] || 'message']))842 res.send(String(req.headers['x-error-property']843 ? err[req.headers['x-error-property']]844 : ('[' + err.type + '] ' + err.message)))845 })846847 app.post('/', function (req, res) {848 res.json(req.body)
6 unmodified lines
855 return function (res) {856 assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count)857 }858}859860function tryRequire (name) {861 try {862 return require(name)863 } catch (e) {864 return {}865 }866}
modified:History.md+10 added
7 unmodified lines
8 * Ignore `Object.prototype` values in settings through `app.set`/`app.get`9 * Invoke `default` with same arguments as types in `res.format`10 * Support proper 205 responses using `res.send`11 * Use `http-errors` for `res.format` error12 * deps: body-parser@1.20.013 - Fix error message for json parse whitespace in `strict`14 - Fix internal error when inflated body exceeds limit15 - Prevent loss of async hooks context16 - Prevent hanging when request already read17 - deps: depd@2.0.018 - deps: http-errors@2.0.019 - deps: on-finished@2.4.120 - deps: qs@6.10.321 - deps: raw-body@2.5.122 * deps: depd@2.0.023 - Replace internal `eval` usage with `Function` constructor24 - Use instance methods on `process` to check for listeners25 * deps: finalhandler@1.2.0
3539 unmodified lines
modified:package.json+1 added-1 removed