Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-barbosa-oliveira committed Nov 30, 2021
2 parents 7d6eb90 + 956e4a0 commit 40f5f31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mapper/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function treatValue(value) {
else if (value.includes('*')) return buildRegEx(value)
else if (value.includes(':')) return getCompareOperator(value)
else if (value === 'now') return normalizeDate(dateToString(new Date()), false)
else if (/^\d*$/.test(value)) return parseInt(value)
else if (parseInt(value).toString() === value) return parseInt(value)
return value
}

Expand Down
6 changes: 4 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.8",
"version": "2.1.9",
"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 All @@ -20,8 +20,10 @@
},
"author": "Lucas Rocha <lucas.rocha@nutes.uepb.edu.br>",
"contributors": [
"Adson Macêdo <agnsoft@hotmail.com>",
"Douglas Rafael <douglas.rafael@nutes.uepb.edu.br>",
"Jefferson Sampaio <jefferson.medeiros@nutes.uepb.edu.br>"
"Jefferson Sampaio <jefferson.medeiros@nutes.uepb.edu.br>",
"Lucas Barbosa <lucas.barbosa@nutes.uepb.edu.br>"
],
"keywords": [
"middleware",
Expand Down
18 changes: 18 additions & 0 deletions test/unit/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ describe('QueryString: Filters', function () {
})
})

context('when query filters contains an integer with a leading zero', function () {
it('should return a JSON with filters params, keeping the leading zero of the number as string', function (done) {
const VALUE = '009'
const result = filter.filters({ value: VALUE }, default_options)
expect(result).to.have.property('value', VALUE)
done()
})
})

context('when query filters contains an integer that exceeds max safe integer', function () {
it('should return a JSON with filters params containing the number as string', function (done) {
const VALUE = '9007199254740999'
const result = filter.filters({ value: VALUE }, default_options)
expect(result).to.have.property('value', VALUE)
done()
})
})

context('when query filters its a object', function () {
it('should ignore the object param and returns another filters', function () {
verify(filter.filters({job: {first: 'developer'}, name: 'lucas', age: '30'}, default_options))
Expand Down

0 comments on commit 40f5f31

Please sign in to comment.