From 7326241718e1fd408ead29b6df2b8c41747cb506 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 3 Nov 2020 00:15:24 +1300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fixed=20server=20error=20for?= =?UTF-8?q?=20repeated=20order=20query=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #12263 - Express parses repeated query parameters as an array (req.query properties). Because there is no clear reason on why not to support this behavior extended order parameter parsing logic to handle arrays. This follows the rule of "liberal inputs, conservative outputs" - Example supported query string for ordering can now look like: `?order=featured&order=published_at asc`, the priority of the order stays the same with the most significant appearing first and least significant last --- core/server/models/plugins/order.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/server/models/plugins/order.js b/core/server/models/plugins/order.js index 0ab1f7b02e..b65c826abb 100644 --- a/core/server/models/plugins/order.js +++ b/core/server/models/plugins/order.js @@ -7,14 +7,22 @@ const order = function order(Bookshelf) { parseOrderOption: function (orderQueryString, withRelated) { let orderAttributes; let result; - let rules; + let rules = []; orderAttributes = this.orderAttributes(); if (withRelated && withRelated.indexOf('count.posts') > -1) { orderAttributes.push('count.posts'); } result = {}; - rules = orderQueryString.split(','); + + // CASE: repeat order query parameter keys are present + if (_.isArray(orderQueryString)) { + orderQueryString.forEach((qs) => { + rules.push(...qs.split(',')); + }); + } else { + rules = orderQueryString.split(','); + } _.each(rules, function (rule) { let match;