Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions docs/_api/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ Many options correspond directly to option defined for the underlying
methods, e.g. `?hasOwnProperty=blah`. (optional, default `false`)
- `options.strictNullHandling` **[Boolean][88]** If true, `?a&b=`
results in `{a: null, b: ''}`. Otherwise, `{a: '', b: ''}`. (optional, default `false`)
- `options.throwOnLimitExceeded` **[Boolean][88]** If true, throws
(surfaced as a `InvalidContentError`) when `arrayLimit` or `parameterLimit`
is exceeded, instead of silently dropping the offending params. (optional, default `false`)

#### Examples

Expand Down Expand Up @@ -476,6 +479,12 @@ All bodyParsers support the following options:
Limits the amount of memory all fields together (except files)
can allocate in bytes.
The default size is `2 * 1024 * 1024` bytes _(2MB)_. (optional, default `2*1024*1024`)
- `options.arrayLimit` **[Number][86]** `urlEncodedBodyParser` only. Only
transform `a[$index]=b` to an array if `$index` is less than `arrayLimit`. (optional, default `20`)
- `options.throwOnLimitExceeded` **[Boolean][88]** `urlEncodedBodyParser`
only. If true, throws when `arrayLimit` or `parameterLimit` is exceeded,
instead of silently dropping the offending params. The error is surfaced
as an `InvalidContentError`. (optional, default `false`)

#### Examples

Expand Down
6 changes: 6 additions & 0 deletions lib/plugins/bodyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ var UnsupportedMediaTypeError = errors.UnsupportedMediaTypeError;
* Limits the amount of memory all fields together (except files)
* can allocate in bytes.
* The default size is `2 * 1024 * 1024` bytes *(2MB)*.
* @param {Number} [options.arrayLimit=20] - `urlEncodedBodyParser` only. Only
* transform `a[$index]=b` to an array if `$index` is less than `arrayLimit`.
* @param {Boolean} [options.throwOnLimitExceeded=false] - `urlEncodedBodyParser`
* only. If true, throws when `arrayLimit` or `parameterLimit` is exceeded,
* instead of silently dropping the offending params. The error is surfaced
* as an `InvalidContentError`.
* @returns {Function} Handler
* @example
* server.use(restify.plugins.bodyParser({
Expand Down
8 changes: 7 additions & 1 deletion lib/plugins/formBodyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ var MIME_TYPE = 'application/x-www-form-urlencoded';
* @public
* @function urlEncodedBodyParser
* @param {Object} options - an option sobject
* @param {Number} [options.arrayLimit=20] - Only transform `a[$index]=b`
* to an array if `$index` is less than `arrayLimit`.
* @param {Boolean} [options.throwOnLimitExceeded=false] - If true, throws
* when `arrayLimit` or `parameterLimit` is exceeded, instead of silently
* dropping the offending params. The error is surfaced as an
* `InvalidContentError`.
* @returns {Function} Handler
*/
function urlEncodedBodyParser(options) {
Expand All @@ -42,7 +48,7 @@ function urlEncodedBodyParser(options) {
}

try {
var params = querystring.parse(req.body);
var params = querystring.parse(req.body, opts);

if (opts.mapParams === true) {
var keys = Object.keys(params);
Expand Down
10 changes: 9 additions & 1 deletion lib/plugins/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var qs = require('qs');
var assert = require('assert-plus');
var errors = require('restify-errors');

/**
* Parses the HTTP query string (i.e., `/foo?id=bar&name=mark`).
Expand Down Expand Up @@ -39,6 +40,9 @@ var assert = require('assert-plus');
* methods, e.g. `?hasOwnProperty=blah`.
* @param {Boolean} [options.strictNullHandling=false] - If true, `?a&b=`
* results in `{a: null, b: ''}`. Otherwise, `{a: '', b: ''}`.
* @param {Boolean} [options.throwOnLimitExceeded=false] - If true, throws
* (surfaced as a `InvalidContentError`) when `arrayLimit` or `parameterLimit`
* is exceeded, instead of silently dropping the offending params.
* @returns {Function} Handler
* @example
* server.use(restify.plugins.queryParser({ mapParams: false }));
Expand All @@ -53,7 +57,11 @@ function queryParser(options) {
return next();
}

req.query = qs.parse(req.getQuery(), opts);
try {
req.query = qs.parse(req.getQuery(), opts);
} catch (e) {
return next(new errors.InvalidContentError(e.message));
}

if (opts.mapParams === true) {
Object.keys(req.query).forEach(function forEach(k) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"once": "^1.4.0",
"pidusage": "^3.0.2",
"pino": "^8.7.0",
"qs": "^6.7.0",
"qs": "^6.15.2",
"restify-errors": "^8.0.2",
"semver": "^7.3.8",
"send": "^1.2.1",
Expand Down