Skip to content

Commit 40f5f31

Browse files
Merge branch 'hotfix/2.1.9'
2 parents 7d6eb90 + 956e4a0 commit 40f5f31

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/mapper/filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function treatValue(value) {
4848
else if (value.includes('*')) return buildRegEx(value)
4949
else if (value.includes(':')) return getCompareOperator(value)
5050
else if (value === 'now') return normalizeDate(dateToString(new Date()), false)
51-
else if (/^\d*$/.test(value)) return parseInt(value)
51+
else if (parseInt(value).toString() === value) return parseInt(value)
5252
return value
5353
}
5454

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-strings-parser",
3-
"version": "2.1.8",
3+
"version": "2.1.9",
44
"description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...",
55
"license": "MIT",
66
"main": "index.js",
@@ -20,8 +20,10 @@
2020
},
2121
"author": "Lucas Rocha <lucas.rocha@nutes.uepb.edu.br>",
2222
"contributors": [
23+
"Adson Macêdo <agnsoft@hotmail.com>",
2324
"Douglas Rafael <douglas.rafael@nutes.uepb.edu.br>",
24-
"Jefferson Sampaio <jefferson.medeiros@nutes.uepb.edu.br>"
25+
"Jefferson Sampaio <jefferson.medeiros@nutes.uepb.edu.br>",
26+
"Lucas Barbosa <lucas.barbosa@nutes.uepb.edu.br>"
2527
],
2628
"keywords": [
2729
"middleware",

test/unit/filters.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ describe('QueryString: Filters', function () {
1111
})
1212
})
1313

14+
context('when query filters contains an integer with a leading zero', function () {
15+
it('should return a JSON with filters params, keeping the leading zero of the number as string', function (done) {
16+
const VALUE = '009'
17+
const result = filter.filters({ value: VALUE }, default_options)
18+
expect(result).to.have.property('value', VALUE)
19+
done()
20+
})
21+
})
22+
23+
context('when query filters contains an integer that exceeds max safe integer', function () {
24+
it('should return a JSON with filters params containing the number as string', function (done) {
25+
const VALUE = '9007199254740999'
26+
const result = filter.filters({ value: VALUE }, default_options)
27+
expect(result).to.have.property('value', VALUE)
28+
done()
29+
})
30+
})
31+
1432
context('when query filters its a object', function () {
1533
it('should ignore the object param and returns another filters', function () {
1634
verify(filter.filters({job: {first: 'developer'}, name: 'lucas', age: '30'}, default_options))

0 commit comments

Comments
 (0)