From 5c08d819edf3e12cc29fdb71a2e562e473ddf8e2 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Wed, 9 Sep 2020 17:48:43 -0300 Subject: [PATCH 1/2] [HOTFIX 2.1.7] Bug fixes Adding second-level keys for ordination. --- lib/mapper/ordination.js | 2 +- test/unit/ordination.spec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/mapper/ordination.js b/lib/mapper/ordination.js index 68dbd15..a558399 100644 --- a/lib/mapper/ordination.js +++ b/lib/mapper/ordination.js @@ -16,7 +16,7 @@ function ordination(query, options) { function processQuery(query) { const result = {} - query = query.replace(/([^\w\s,-])|(\s{1,})/gi, '') + query = query.replace(/([^\w\s,.-])|(\s{1,})/gi, '') query.split(',').forEach(function (elem) { elem = elem.trim() if (elem[0] === '-') result[elem.substr(1)] = -1 diff --git a/test/unit/ordination.spec.js b/test/unit/ordination.spec.js index 2092932..02297e2 100644 --- a/test/unit/ordination.spec.js +++ b/test/unit/ordination.spec.js @@ -10,6 +10,14 @@ describe('QueryString: Ordination', function () { }) }) + context('when ordination query is a second-level string', function () { + it('should return a JSON with order params', function (done) { + const result = ordination.sort({sort: '-user.age'}, default_options) + expect(result['user.age']).to.eql(-1) + done() + }) + }) + context('when ordination query is an array of strings', function () { it('should return a JSON with order params', function (done) { verify(ordination.sort({sort: ['-name,age', 'created_at']}, default_options)) From 52465bd3e66eebed5c5f8b131aa36fc2db74c9ac Mon Sep 17 00:00:00 2001 From: Douglas Rafael Date: Thu, 10 Sep 2020 17:04:00 -0300 Subject: [PATCH 2/2] Adjustments for version 2.1.7 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d847549..1303e33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "query-strings-parser", - "version": "2.1.6", + "version": "2.1.7", "description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...", "license": "MIT", "main": "index.js", @@ -44,7 +44,7 @@ "devDependencies": { "chai": "^4.2.0", "express": "^4.17.1", - "mocha": "^8.1.1", + "mocha": "^8.1.3", "nyc": "^15.1.0", "supertest": "^4.0.2" }