deps: body-parser@2.0.0-beta.1

This commit is contained in:
Douglas Christopher Wilson 2021-12-17 23:02:38 -05:00
parent 1574925cad
commit af341b0f09
8 changed files with 23 additions and 14 deletions

View File

@ -3,6 +3,10 @@
This incorporates all changes after 4.17.1 up to 4.17.2. This incorporates all changes after 4.17.1 up to 4.17.2.
* deps: body-parser@2.0.0-beta.1
- `req.body` is no longer always initialized to `{}`
- `urlencoded` parser now defaults `extended` to `false`
- Use `on-finished` to determine when body read
* deps: router@2.0.0-beta.1 * deps: router@2.0.0-beta.1
- Add new `?`, `*`, and `+` parameter modifiers - Add new `?`, `*`, and `+` parameter modifiers
- Internalize private `router.process_params` method - Internalize private `router.process_params` method

View File

@ -16,7 +16,7 @@ app.set('views', path.join(__dirname, 'views'));
// middleware // middleware
app.use(express.urlencoded({ extended: false })) app.use(express.urlencoded())
app.use(session({ app.use(session({
resave: false, // don't save session if unmodified resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored saveUninitialized: false, // don't create session until something stored
@ -100,6 +100,7 @@ app.get('/login', function(req, res){
}); });
app.post('/login', function(req, res){ app.post('/login', function(req, res){
if (!req.body) return res.sendStatus(400)
authenticate(req.body.username, req.body.password, function(err, user){ authenticate(req.body.username, req.body.password, function(err, user){
if (user) { if (user) {
// Regenerate session when signing in // Regenerate session when signing in

View File

@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== 'test') app.use(logger(':method :url'))
app.use(cookieParser('my secret here')); app.use(cookieParser('my secret here'));
// parses x-www-form-urlencoded // parses x-www-form-urlencoded
app.use(express.urlencoded({ extended: false })) app.use(express.urlencoded())
app.get('/', function(req, res){ app.get('/', function(req, res){
if (req.cookies.remember) { if (req.cookies.remember) {
@ -36,7 +36,11 @@ app.get('/forget', function(req, res){
app.post('/', function(req, res){ app.post('/', function(req, res){
var minute = 60000; var minute = 60000;
if (req.body.remember) res.cookie('remember', 1, { maxAge: minute });
if (req.body && req.body.remember) {
res.cookie('remember', 1, { maxAge: minute })
}
res.redirect('back'); res.redirect('back');
}); });

View File

@ -30,7 +30,7 @@
"dependencies": { "dependencies": {
"accepts": "~1.3.7", "accepts": "~1.3.7",
"array-flatten": "2.1.1", "array-flatten": "2.1.1",
"body-parser": "1.19.1", "body-parser": "2.0.0-beta.1",
"content-disposition": "0.5.4", "content-disposition": "0.5.4",
"content-type": "~1.0.4", "content-type": "~1.0.4",
"cookie": "0.4.1", "cookie": "0.4.1",

View File

@ -312,7 +312,7 @@ describe('express.json()', function () {
.post('/') .post('/')
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.send('{"user":"tobi"}') .send('{"user":"tobi"}')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })
@ -344,7 +344,7 @@ describe('express.json()', function () {
.post('/') .post('/')
.set('Content-Type', 'application/x-json') .set('Content-Type', 'application/x-json')
.send('{"user":"tobi"}') .send('{"user":"tobi"}')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })

View File

@ -182,7 +182,7 @@ describe('express.raw()', function () {
var test = request(this.app).post('/') var test = request(this.app).post('/')
test.set('Content-Type', 'application/octet-stream') test.set('Content-Type', 'application/octet-stream')
test.write(Buffer.from('000102', 'hex')) test.write(Buffer.from('000102', 'hex'))
test.expect(200, '{}', done) test.expect(200, '', done)
}) })
}) })
@ -211,7 +211,7 @@ describe('express.raw()', function () {
var test = request(this.app).post('/') var test = request(this.app).post('/')
test.set('Content-Type', 'application/x-foo') test.set('Content-Type', 'application/x-foo')
test.write(Buffer.from('000102', 'hex')) test.write(Buffer.from('000102', 'hex'))
test.expect(200, '{}', done) test.expect(200, '', done)
}) })
}) })

View File

@ -195,7 +195,7 @@ describe('express.text()', function () {
.post('/') .post('/')
.set('Content-Type', 'text/plain') .set('Content-Type', 'text/plain')
.send('user is tobi') .send('user is tobi')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })
@ -225,7 +225,7 @@ describe('express.text()', function () {
.post('/') .post('/')
.set('Content-Type', 'text/xml') .set('Content-Type', 'text/xml')
.send('<user>tobi</user>') .send('<user>tobi</user>')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })

View File

@ -73,12 +73,12 @@ describe('express.urlencoded()', function () {
.expect(200, '{"user":"tobi"}', done) .expect(200, '{"user":"tobi"}', done)
}) })
it('should parse extended syntax', function (done) { it('should not parse extended syntax', function (done) {
request(this.app) request(this.app)
.post('/') .post('/')
.set('Content-Type', 'application/x-www-form-urlencoded') .set('Content-Type', 'application/x-www-form-urlencoded')
.send('user[name][first]=Tobi') .send('user[name][first]=Tobi')
.expect(200, '{"user":{"name":{"first":"Tobi"}}}', done) .expect(200, '{"user[name][first]":"Tobi"}', done)
}) })
describe('with extended option', function () { describe('with extended option', function () {
@ -441,7 +441,7 @@ describe('express.urlencoded()', function () {
.post('/') .post('/')
.set('Content-Type', 'application/x-www-form-urlencoded') .set('Content-Type', 'application/x-www-form-urlencoded')
.send('user=tobi') .send('user=tobi')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })
@ -473,7 +473,7 @@ describe('express.urlencoded()', function () {
.post('/') .post('/')
.set('Content-Type', 'application/x-foo') .set('Content-Type', 'application/x-foo')
.send('user=tobi') .send('user=tobi')
.expect(200, '{}', done) .expect(200, '', done)
}) })
}) })