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 Dec 16, 2021
1 parent d0a214b commit 8e4def6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
2.x
===

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

1.19.1 / 2021-12-10
===================

Expand Down
10 changes: 4 additions & 6 deletions README.md
Expand Up @@ -237,9 +237,7 @@ encoded into the URL-encoded format, allowing for a JSON-like experience
with URL-encoded. For more information, please
[see the qs library](https://www.npmjs.org/package/qs#readme).

Defaults to `true`, but using the default has been deprecated. Please
research into the difference between `qs` and `querystring` and choose the
appropriate setting.
Defaults to `false`.

##### inflate

Expand Down Expand Up @@ -380,15 +378,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 @@ -408,7 +406,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
Expand Up @@ -16,7 +16,6 @@ var bytes = require('bytes')
var contentType = require('content-type')
var createError = require('http-errors')
var debug = require('debug')('body-parser:urlencoded')
var deprecate = require('depd')('body-parser')
var read = require('../read')
var typeis = require('type-is')

Expand All @@ -43,12 +42,7 @@ var parsers = Object.create(null)
function urlencoded (options) {
var opts = options || {}

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

var extended = opts.extended !== false
var extended = Boolean(opts.extended)
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
Expand Down
4 changes: 2 additions & 2 deletions test/urlencoded.js
Expand Up @@ -67,12 +67,12 @@ describe('bodyParser.urlencoded()', function () {
.expect(200, '{"user":"tobi"}', done)
})

it('should parse extended syntax', function (done) {
it('should not parse extended syntax', function (done) {
request(this.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 8e4def6

Please sign in to comment.