Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add ability to control maxKeys in the querystring parser.

As of 8a98c2f the Node querystring parser
will only extract 1000 parameters by default. This change puts the default
back to unlimited (to retain the original formidable behaviour) while allowing
it to be set via the `maxFields` option.

At the moment this option only affects the QuerystringParser, but could be
extended to apply to all the parsers for which it makes sense.
  • Loading branch information...
commit 05e98f69394974d7622a08fd31178ac4fdd13a15 1 parent 12f1d59
James Howe authored
5 Readme.md
Source Rendered
@@ -105,6 +105,11 @@ Limits the amount of memory a field (not file) can allocate in bytes.
105 105 If this value is exceeded, an `'error'` event is emitted. The default
106 106 size is 2MB.
107 107
  108 +```javascript
  109 +form.maxFields = 0;
  110 +```
  111 +Limits the number of fields that the querystring parser will decode. Defaults
  112 +to 0 (unlimited).
108 113
109 114 ```javascript
110 115 form.hash = false;
4 lib/incoming_form.js
@@ -22,6 +22,7 @@ function IncomingForm(opts) {
22 22 this.error = null;
23 23 this.ended = false;
24 24
  25 + this.maxFields = opts.maxFields || 0;
25 26 this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024;
26 27 this.keepExtensions = opts.keepExtensions || false;
27 28 this.uploadDir = opts.uploadDir || os.tmpDir();
@@ -410,7 +411,7 @@ IncomingForm.prototype._fileName = function(headerValue) {
410 411 IncomingForm.prototype._initUrlencoded = function() {
411 412 this.type = 'urlencoded';
412 413
413   - var parser = new QuerystringParser()
  414 + var parser = new QuerystringParser(this.maxFields)
414 415 , self = this;
415 416
416 417 parser.onField = function(key, val) {
@@ -525,3 +526,4 @@ IncomingForm.prototype._maybeEnd = function() {
525 526
526 527 this.emit('end');
527 528 };
  529 +
8 lib/querystring_parser.js
@@ -4,7 +4,8 @@ if (global.GENTLY) require = GENTLY.hijack(require);
4 4 // If I find time I'll rewrite this to be fully streaming as well
5 5 var querystring = require('querystring');
6 6
7   -function QuerystringParser() {
  7 +function QuerystringParser(maxKeys) {
  8 + this.maxKeys = maxKeys;
8 9 this.buffer = '';
9 10 };
10 11 exports.QuerystringParser = QuerystringParser;
@@ -15,11 +16,12 @@ QuerystringParser.prototype.write = function(buffer) {
15 16 };
16 17
17 18 QuerystringParser.prototype.end = function() {
18   - var fields = querystring.parse(this.buffer);
  19 + var fields = querystring.parse(this.buffer, '&', '=', { maxKeys: this.maxKeys });
19 20 for (var field in fields) {
20 21 this.onField(field, fields[field]);
21 22 }
22 23 this.buffer = '';
23 24
24 25 this.onEnd();
25   -};
  26 +};
  27 +

0 comments on commit 05e98f6

Please sign in to comment.
Something went wrong with that request. Please try again.