Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasrafael committed Sep 10, 2020
2 parents 7e61b3d + 52465bd commit 179b441
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mapper/ordination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/ordination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 179b441

Please sign in to comment.