Skip to content

Commit

Permalink
Add queryStringParser settings to parser middleware
Browse files Browse the repository at this point in the history
Signed-off-by: David Janas <davidjanasr@gmail.com>
  • Loading branch information
drj17 committed Aug 12, 2020
1 parent acf11ed commit 458184f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/strapi/lib/middlewares/parser/defaults.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"parser": {
"enabled": true,
"multipart": true
"multipart": true,
"queryStringParser": {
"arrayLimit": 100,
"depth": 20
}
}
}
10 changes: 5 additions & 5 deletions packages/strapi/lib/middlewares/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

const body = require('koa-body');
const qs = require('qs');
const { omit } = require('lodash');

/**
* Body parser hook
*/
const addQsParser = app => {
const addQsParser = (app, settings) => {
Object.defineProperty(app.request, 'query', {
configurable: false,
enumerable: true,
Expand All @@ -16,7 +17,7 @@ const addQsParser = app => {
get() {
const qstr = this.querystring;
const cache = (this._querycache = this._querycache || {});
return cache[qstr] || (cache[qstr] = qs.parse(qstr, { depth: 20 }));
return cache[qstr] || (cache[qstr] = qs.parse(qstr, settings));
},

/*
Expand All @@ -40,14 +41,13 @@ module.exports = strapi => {
// disable for graphql
// TODO: find a better way later
if (ctx.url === '/graphql') return next();

return body({
patchKoa: true,
...strapi.config.middleware.settings.parser,
...omit(strapi.config.middleware.settings.parser, 'queryStringParser'),
})(ctx, next);
});

addQsParser(strapi.app);
addQsParser(strapi.app, strapi.config.get('middleware.settings.parser.queryStringParser'));
},
};
};

0 comments on commit 458184f

Please sign in to comment.