Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebase: Generic Body Parser implemented #524

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9eb5ab4
chore: add support for OSSF scorecard reporting (#522)
inigomarquinez May 14, 2024
1c2f923
Added support for external parsers to bodyParser.json()
Nov 21, 2017
2f4913c
removed test dependency on json-bigint
Nov 21, 2017
6daefb5
reworked doc to describe json parser() func better
Nov 21, 2017
b740295
added parser() option and doc for .text()
Nov 21, 2017
cf3a8e3
added parser() option and doc for .raw()
Nov 21, 2017
2468f72
added parser() option and doc for .urlencoded()
Nov 21, 2017
d75adee
cleanup to satisfy linter
Nov 21, 2017
8224cda
added generic parser
Nov 21, 2017
a5adc82
converted json parser to use generic parser
Nov 21, 2017
c572330
converted raw parser to use generic parser
Nov 21, 2017
7390c89
converted text parser to use generic parser
Nov 21, 2017
f4f9d84
converted urlencoded parser to use generic parser
Nov 21, 2017
10eb0af
cleanup / fix linter warnings
Nov 21, 2017
67060ca
removed items from README
Nov 21, 2017
e6f6004
added bodyParser.generic() getter
Nov 21, 2017
07e0602
cleanup / fix linter warnings
Nov 21, 2017
bb7697a
fixed tests after rebase
sdellysse Apr 17, 2020
6a7c24d
satisfying linter
sdellysse Apr 17, 2020
bc7454b
Ref'd genParser via the bodyparser getter to signal how third party p…
sdellysse Apr 17, 2020
519f306
removed dep on object-assign, which didnt support node < 0.10
sdellysse Apr 17, 2020
cdf46f0
minor text cleanup
sdellysse Apr 17, 2020
8ac04fd
🔧 add debug script
ctcpip May 24, 2024
1a43910
🐛 fix object merging
ctcpip May 24, 2024
86804fe
🔥 clean up
ctcpip May 24, 2024
88f84bd
💚 remove node < 4 from CI
ctcpip May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added parser() option and doc for .urlencoded()
Shawn Dellysse authored and ctcpip committed May 24, 2024

Verified

This commit was signed with the committer’s verified signature.
driesvints Dries Vints
commit 2468f724ce616ec7f200a22cb7c1a0ee398cf6e3
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -302,6 +302,16 @@ The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`
where `buf` is a `Buffer` of the raw request body and `encoding` is the
encoding of the request. The parsing can be aborted by throwing an error.

##### parser

The `parser` option, if supplied, is used to in place of the default parser to
convert the request body into a Javascript object. If this option is supplied,
both the `extended` and `parameterLimit` options are ignored.

```javascript
parser(body) -> req.body
```

## Errors

The middlewares provided by this module create errors using the
6 changes: 4 additions & 2 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
@@ -56,9 +56,11 @@ function urlencoded (options) {
}

// create the appropriate query parser
var queryparse = extended
var parser = opts.parser || (
extended
? extendedparser(opts)
: simpleparser(opts)
)

// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
@@ -67,7 +69,7 @@ function urlencoded (options) {

function parse (body) {
return body.length
? queryparse(body)
? parser(body)
: {}
}

10 changes: 10 additions & 0 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,16 @@ describe('bodyParser.urlencoded()', function () {
.expect(200, '{"user":"tobi"}', done)
})

it('should parse x-www-form-urlencoded with custom parser', function (done) {
request(createServer({
parser: function (input) { return input.toUpperCase() }
}))
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user=tobi')
.expect(200, '"USER=TOBI"', done)
})

it('should 400 when invalid content-length', function (done) {
var urlencodedParser = bodyParser.urlencoded()
var server = createServer(function (req, res, next) {