diff --git a/lib/mapper/filters.js b/lib/mapper/filters.js index fd32141..d434fb4 100644 --- a/lib/mapper/filters.js +++ b/lib/mapper/filters.js @@ -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 } diff --git a/package.json b/package.json index 308473e..62998cf 100644 --- a/package.json +++ b/package.json @@ -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", @@ -20,8 +20,10 @@ }, "author": "Lucas Rocha ", "contributors": [ + "Adson MacĂȘdo ", "Douglas Rafael ", - "Jefferson Sampaio " + "Jefferson Sampaio ", + "Lucas Barbosa " ], "keywords": [ "middleware", diff --git a/test/unit/filters.spec.js b/test/unit/filters.spec.js index 19b73da..b0c3cf5 100644 --- a/test/unit/filters.spec.js +++ b/test/unit/filters.spec.js @@ -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))