Skip to content

Commit

Permalink
Default urlencoded extended option to false
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 30, 2014
1 parent efb1e7d commit d3021d6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.x
===

* `urlencoded` parser now defaults `extended` to `false`

1.9.2 / 2014-10-27
==================

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Returns middleware that only parses `urlencoded` bodies. This parser accepts onl

The options are:

- `extended` - parse extended syntax with the [qs](https://www.npmjs.org/package/qs#readme) module. (default: `true`)
- `extended` - parse extended syntax with the [qs](https://www.npmjs.org/package/qs#readme) module. (default: `false`)
- `inflate` - if deflated bodies will be inflated. (default: `true`)
- `limit` - maximum request body size. (default: `<100kb>`)
- `parameterLimit` - maximum number of parameters. (default: `1000`)
Expand Down Expand Up @@ -120,15 +120,15 @@ var bodyParser = require('body-parser')
var app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.urlencoded())

// parse application/json
app.use(bodyParser.json())

app.use(function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.write('you posted:\n')
res.end(JSON.stringify(req.body, null, 2))
res.end(req.body ? JSON.stringify(req.body, null, 2) : 'nothing')
})
```

Expand All @@ -146,7 +146,7 @@ var app = express()
var jsonParser = bodyParser.json()

// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
var urlencodedParser = bodyParser.urlencoded()

// POST /login gets urlencoded bodies
app.post('/login', urlencodedParser, function (req, res) {
Expand Down
8 changes: 1 addition & 7 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

var bytes = require('bytes')
var deprecate = require('depd')('body-parser')
var read = require('../read')
var typer = require('media-typer')
var typeis = require('type-is')
Expand Down Expand Up @@ -38,12 +37,7 @@ var parsers = Object.create(null)
function urlencoded(options){
options = options || {};

// notice because option default will flip in next major
if (options.extended === undefined) {
deprecate('undefined extended: provide extended option')
}

var extended = options.extended !== false
var extended = Boolean(options.extended)
var inflate = options.inflate !== false
var limit = typeof options.limit !== 'number'
? bytes(options.limit || '100kb')
Expand Down
4 changes: 2 additions & 2 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ describe('bodyParser.urlencoded()', function(){
.expect(200, '{}', done)
})

it('should parse extended syntax', function(done){
it('should not parse extended syntax', function(done){
request(server)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user[name][first]=Tobi')
.expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)
.expect(200, '{"user[name][first]":"Tobi"}', done)
})

describe('with extended option', function(){
Expand Down

0 comments on commit d3021d6

Please sign in to comment.