mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
🐛 Fixed server error for repeated order query parameter
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
This commit is contained in:
parent
14ac6168ac
commit
7326241718
1 changed files with 10 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue