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/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" } 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))