Skip to content

Commit a3a2c71

Browse files
committed
Merge branch 'hotfix/2.1.10'
2 parents 40f5f31 + 4b482fa commit a3a2c71

File tree

8 files changed

+112
-107
lines changed

8 files changed

+112
-107
lines changed

lib/mapper/filters.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,15 @@ function buildRegEx(value) {
9292

9393
function addAccentsRegex(string) {
9494
return string.replace(/a/g, '[a,á,à,ä,â,ã]')
95-
.replace(/e/g, '[e,é,ë,ê]')
96-
.replace(/i/g, '[i,í,ï]')
97-
.replace(/o/g, '[o,ó,ö,ò,ô]')
98-
.replace(/u/g, '[u,ü,ú,ù]')
95+
.replace(/A/g, '[A,Á,À,Ä,Â,Ã]')
96+
.replace(/e/g, '[e,é,ë,ê]')
97+
.replace(/E/g, '[E,É,Ë,Ê]')
98+
.replace(/i/g, '[i,í,ï]')
99+
.replace(/I/g, '[I,Í,Ï]')
100+
.replace(/o/g, '[o,ó,ö,ò,ô]')
101+
.replace(/O/g, '[O,Ó,Ö,Ò,Ô]')
102+
.replace(/u/g, '[u,ü,ú,ù]')
103+
.replace(/U/g, '[U,Ü,Ú,Ù]')
99104
}
100105

101106
function parseDate(query, options) {

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-strings-parser",
3-
"version": "2.1.9",
3+
"version": "2.1.10",
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",
@@ -47,8 +47,8 @@
4747
"devDependencies": {
4848
"chai": "^4.3.4",
4949
"express": "^4.17.1",
50-
"mocha": "^9.0.3",
50+
"mocha": "^9.1.3",
5151
"nyc": "^15.1.0",
52-
"supertest": "^6.1.4"
52+
"supertest": "^6.1.6"
5353
}
5454
}

test/integration/index.default.config.spec.js

+47-47
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('queryFilter()', function () {
4242

4343
context('when query contains pagination param with string limit as skip', function () {
4444
it('should return req.query with set pagination params', function () {
45-
const expect_pagination = {limit: Number.MAX_SAFE_INTEGER, skip: 2}
45+
const expect_pagination = { limit: Number.MAX_SAFE_INTEGER, skip: 2 }
4646

4747
const options = JSON.parse(JSON.stringify(default_options))
4848
options.default.pagination.limit = expect_pagination.limit
@@ -60,7 +60,7 @@ describe('queryFilter()', function () {
6060

6161
context('when query contains pagination param with string skip', function () {
6262
it('should return req.query with set pagination params', function () {
63-
const expect_pagination = {limit: 10, skip: 0}
63+
const expect_pagination = { limit: 10, skip: 0 }
6464

6565
const options = JSON.parse(JSON.stringify(default_options))
6666
options.default.pagination.limit = expect_pagination.limit
@@ -78,7 +78,7 @@ describe('queryFilter()', function () {
7878

7979
context('when query contains ordination param', function () {
8080
it('should return req.query with set ordination params', function () {
81-
const expect_sort = {name: 1, age: -1}
81+
const expect_sort = { name: 1, age: -1 }
8282

8383
const options = JSON.parse(JSON.stringify(default_options))
8484
options.default.sort = expect_sort
@@ -95,7 +95,7 @@ describe('queryFilter()', function () {
9595

9696
context('when query contains fields param', function () {
9797
it('should return req.query with set field params', function () {
98-
const expect_fields = {name: 1, age: 1}
98+
const expect_fields = { name: 1, age: 1 }
9999

100100
const options = JSON.parse(JSON.stringify(default_options))
101101
options.default.fields = expect_fields
@@ -112,7 +112,7 @@ describe('queryFilter()', function () {
112112

113113
context('when query contains simple filters param', function () {
114114
it('should return req.query with set field params', function () {
115-
const expect_filters = {name: 'lucas', age: 30}
115+
const expect_filters = { name: 'lucas', age: 30 }
116116

117117
const options = JSON.parse(JSON.stringify(default_options))
118118
options.default.filters = expect_filters
@@ -138,17 +138,17 @@ describe('queryFilter()', function () {
138138
name: { '$options': 'i', '$regex': 'd[o,ó,ö,ò,ô][u,ü,ú,ù]gl[a,á,à,ä,â,ã]s$' }
139139
},
140140
{
141-
name: { '$options': 'i', '$regex': 'j[o,ó,ö,ò,ô]rg[e,é,ë,ê]' }
141+
name: { '$options': 'i', '$regex': 'J[O,Ó,Ö,Ò,Ô]RG[E,É,Ë,Ê]' }
142142
}],
143143
'school.name': 'UEPB',
144144
'timestamp': '2018-12-05T00:00:00',
145-
'$or': [{job: 'Developer'}, {job: 'Engineer'}]
145+
'$or': [{ job: 'Developer' }, { job: 'Engineer' }]
146146
}
147147

148148
const options = JSON.parse(JSON.stringify(default_options))
149149
options.default.filters = expect_filters
150150

151-
const query = '?name=lucas****&name=*****douglas&name=*****jorge*****&.school.name.=UEPB'
151+
const query = '?name=lucas****&name=*****douglas&name=*****JORGE*****&.school.name.=UEPB'
152152
.concat('&timestamp=2018-12-05&job=Developer,Engineer')
153153

154154
return request(app)
@@ -163,9 +163,9 @@ describe('queryFilter()', function () {
163163
it('should return req.query with set field params', function () {
164164
const expect_filters = {
165165
name: 'lucas',
166-
age: {$gt: 30},
167-
timestamp: {$gt: '2018-12-05T00:00:00'},
168-
created_at: {$lte: '2018-12-06T00:00:00'},
166+
age: { $gt: 30 },
167+
timestamp: { $gt: '2018-12-05T00:00:00' },
168+
created_at: { $lte: '2018-12-06T00:00:00' },
169169
sleep_hour: '22:40'
170170
}
171171

@@ -185,10 +185,10 @@ describe('queryFilter()', function () {
185185
it('should return req.query with set field params (with $ne filter)', function () {
186186
const expect_filters = {
187187
name: 'lucas',
188-
age: {$gt: 30},
189-
type: {$ne: 'admin'},
190-
timestamp: {$gt: '2018-12-05T00:00:00'},
191-
created_at: {$lte: '2018-12-06T00:00:00'},
188+
age: { $gt: 30 },
189+
type: { $ne: 'admin' },
190+
timestamp: { $gt: '2018-12-05T00:00:00' },
191+
created_at: { $lte: '2018-12-06T00:00:00' },
192192
sleep_hour: '22:40'
193193
}
194194

@@ -210,8 +210,8 @@ describe('queryFilter()', function () {
210210
it('should return req.query with set start_at params as today', function () {
211211
const expect_filters = {
212212
$and: [
213-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
214-
{created_at: {$gte: normalizeDate(dateToString(new Date()), true)}}
213+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
214+
{ created_at: { $gte: normalizeDate(dateToString(new Date()), true) } }
215215
]
216216
}
217217

@@ -230,8 +230,8 @@ describe('queryFilter()', function () {
230230
it('should return req.query with set end_at params as today', function () {
231231
const expect_filters = {
232232
$and: [
233-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
234-
{created_at: {$gte: '2019-02-05T00:00:00'}}
233+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
234+
{ created_at: { $gte: '2019-02-05T00:00:00' } }
235235
]
236236
}
237237

@@ -250,8 +250,8 @@ describe('queryFilter()', function () {
250250
it('should return req.query with set start_at params as date', function () {
251251
const expect_filters = {
252252
$and: [
253-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
254-
{created_at: {$gte: '2018-12-05T00:00:01'}}
253+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
254+
{ created_at: { $gte: '2018-12-05T00:00:01' } }
255255
]
256256
}
257257

@@ -271,8 +271,8 @@ describe('queryFilter()', function () {
271271
it('should return req.query with set start_at params as dateTime', function () {
272272
const expect_filters = {
273273
$and: [
274-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
275-
{created_at: {$gte: '2018-12-05T00:00:00'}}
274+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
275+
{ created_at: { $gte: '2018-12-05T00:00:00' } }
276276
]
277277
}
278278

@@ -292,8 +292,8 @@ describe('queryFilter()', function () {
292292

293293
const expect_filters = {
294294
$and: [
295-
{created_at: {$lt: '2018-12-11T00:00:00'}},
296-
{created_at: {$gte: '2018-12-01T00:00:00'}}]
295+
{ created_at: { $lt: '2018-12-11T00:00:00' } },
296+
{ created_at: { $gte: '2018-12-01T00:00:00' } }]
297297
}
298298

299299

@@ -313,8 +313,8 @@ describe('queryFilter()', function () {
313313

314314
const expect_filters = {
315315
$and: [
316-
{created_at: {$lt: '2018-12-11T03:02:01'}},
317-
{created_at: {$gte: '2018-12-01T01:02:03'}}]
316+
{ created_at: { $lt: '2018-12-11T03:02:01' } },
317+
{ created_at: { $gte: '2018-12-01T01:02:03' } }]
318318
}
319319

320320
const options = JSON.parse(JSON.stringify(default_options))
@@ -332,8 +332,8 @@ describe('queryFilter()', function () {
332332
it('should return req.query with period as day and start_at param', function () {
333333
const expect_filters = {
334334
$and: [
335-
{created_at: {$lt: '2019-01-26T23:59:59'}},
336-
{created_at: {$gte: '2019-01-24T00:00:00'}}
335+
{ created_at: { $lt: '2019-01-26T23:59:59' } },
336+
{ created_at: { $gte: '2019-01-24T00:00:00' } }
337337
]
338338
}
339339

@@ -352,8 +352,8 @@ describe('queryFilter()', function () {
352352
it('should return req.query with period as day and end_at param', function () {
353353
const expect_filters = {
354354
$and: [
355-
{created_at: {$lt: '2019-01-26T00:00:00'}},
356-
{created_at: {$gte: '2019-01-24T00:00:00'}}
355+
{ created_at: { $lt: '2019-01-26T00:00:00' } },
356+
{ created_at: { $gte: '2019-01-24T00:00:00' } }
357357
]
358358
}
359359

@@ -372,8 +372,8 @@ describe('queryFilter()', function () {
372372
it('should return req.query with period as week and start_at param', function () {
373373
const expect_filters = {
374374
$and: [
375-
{created_at: {$lt: '2019-01-26T23:59:59'}},
376-
{created_at: {$gte: '2019-01-19T00:00:00'}}
375+
{ created_at: { $lt: '2019-01-26T23:59:59' } },
376+
{ created_at: { $gte: '2019-01-19T00:00:00' } }
377377
]
378378
}
379379

@@ -392,8 +392,8 @@ describe('queryFilter()', function () {
392392
it('should return req.query with period as week and end_at param', function () {
393393
const expect_filters = {
394394
$and: [
395-
{created_at: {$lt: '2019-01-26T23:59:59'}},
396-
{created_at: {$gte: '2019-01-19T00:00:00'}}
395+
{ created_at: { $lt: '2019-01-26T23:59:59' } },
396+
{ created_at: { $gte: '2019-01-19T00:00:00' } }
397397
]
398398
}
399399

@@ -412,8 +412,8 @@ describe('queryFilter()', function () {
412412
it('should return req.query with period as month and start_at param', function () {
413413
const expect_filters = {
414414
$and: [
415-
{created_at: {$lt: '2019-02-24T23:59:59'}},
416-
{created_at: {$gte: '2019-01-24T00:00:00'}}
415+
{ created_at: { $lt: '2019-02-24T23:59:59' } },
416+
{ created_at: { $gte: '2019-01-24T00:00:00' } }
417417
]
418418
}
419419

@@ -432,8 +432,8 @@ describe('queryFilter()', function () {
432432
it('should return req.query with period as month and end_at param', function () {
433433
const expect_filters = {
434434
$and: [
435-
{created_at: {$lt: '2019-01-24T23:59:59'}},
436-
{created_at: {$gte: '2018-12-24T00:00:00'}}
435+
{ created_at: { $lt: '2019-01-24T23:59:59' } },
436+
{ created_at: { $gte: '2018-12-24T00:00:00' } }
437437
]
438438
}
439439

@@ -452,8 +452,8 @@ describe('queryFilter()', function () {
452452
it('should return req.query with period as year and start_at param', function () {
453453
const expect_filters = {
454454
$and: [
455-
{created_at: {$lt: '2019-02-24T23:59:59'}},
456-
{created_at: {$gte: '2018-02-24T00:00:00'}}
455+
{ created_at: { $lt: '2019-02-24T23:59:59' } },
456+
{ created_at: { $gte: '2018-02-24T00:00:00' } }
457457
]
458458
}
459459

@@ -472,8 +472,8 @@ describe('queryFilter()', function () {
472472
it('should return req.query with period as year and end_at param', function () {
473473
const expect_filters = {
474474
$and: [
475-
{created_at: {$lt: '2019-02-24T23:59:59'}},
476-
{created_at: {$gte: '2018-02-24T00:00:00'}}
475+
{ created_at: { $lt: '2019-02-24T23:59:59' } },
476+
{ created_at: { $gte: '2018-02-24T00:00:00' } }
477477
]
478478
}
479479

@@ -492,8 +492,8 @@ describe('queryFilter()', function () {
492492
it('should return req.query with today start_at for invalid period', function () {
493493
const expect_filters = {
494494
$and: [
495-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
496-
{created_at: {$gte: normalizeDate(dateToString(new Date()), true)}}
495+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
496+
{ created_at: { $gte: normalizeDate(dateToString(new Date()), true) } }
497497
]
498498
}
499499

@@ -512,8 +512,8 @@ describe('queryFilter()', function () {
512512
it('should return req.query with today end_at for invalid period', function () {
513513
const expect_filters = {
514514
$and: [
515-
{created_at: {$lt: normalizeDate(dateToString(new Date()), false)}},
516-
{created_at: {$gte: '2018-12-05T00:00:01'}}
515+
{ created_at: { $lt: normalizeDate(dateToString(new Date()), false) } },
516+
{ created_at: { $gte: '2018-12-05T00:00:01' } }
517517
]
518518
}
519519

test/unit/fields.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ describe('QueryString: Fields', function () {
55

66
context('when query fields are a simple string', function () {
77
it('should return a JSON with field params', function (done) {
8-
const query = {fields: 'name,age,created_at'}
8+
const query = { fields: 'name,age,created_at' }
99
verify(fields.fields(query, default_options))
1010
done()
1111
})
1212
})
1313

1414
context('when query fields are an array of strings', function () {
1515
it('should return a JSON with field params', function (done) {
16-
const query = {fields: ['name,age', 'created_at']}
16+
const query = { fields: ['name,age', 'created_at'] }
1717
verify(fields.fields(query, default_options))
1818
done()
1919
})
2020
})
2121

2222
context('when there are blank spaces between query fields', function () {
2323
it('should return a JSON with field params, ignoring the blank space', function (done) {
24-
const query = {fields: ' name , name, age , created_at'}
24+
const query = { fields: ' name , name, age , created_at' }
2525
verify(fields.fields(query, default_options))
2626
done()
2727
})
2828
})
2929

3030
context('when there are null fields in query fields', function () {
3131
it('should return a JSON with field params, ignoring the null fields', function (done) {
32-
const query = {fields: ',,name,,,age,,,,,created_at,,'}
32+
const query = { fields: ',,name,,,age,,,,,created_at,,' }
3333
verify(fields.fields(query, default_options))
3434
done()
3535
})
3636
})
3737

3838
context('when there are special characters in query fields', function () {
3939
it('should return a JSON with field params, ignoring the special characteres', function (done) {
40-
const query = {fields: ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t '}
40+
const query = { fields: ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t ' }
4141
verify(fields.fields(query, default_options))
4242
done()
4343

@@ -54,16 +54,16 @@ describe('QueryString: Fields', function () {
5454

5555
context('when use custom params', function () {
5656
it('should return a JSON with custom params', function () {
57-
const custom_options = {default: {fields: {name: 1, age: 1, _id: 0}}}
57+
const custom_options = { default: { fields: { name: 1, age: 1, _id: 0 } } }
5858
const result = fields.fields({}, custom_options)
5959
expect(result.name).to.eql(custom_options.default.fields.name)
6060
expect(result.age).to.eql(custom_options.default.fields.age)
6161
expect(result._id).to.eql(custom_options.default.fields._id)
6262
})
6363

6464
it('should return a JSON with custom params and those of the query', function () {
65-
const custom_options = {default: {fields: {name: 1, _id: 1}}}
66-
const result = fields.fields({fields: 'age'}, custom_options)
65+
const custom_options = { default: { fields: { name: 1, _id: 1 } } }
66+
const result = fields.fields({ fields: 'age' }, custom_options)
6767
expect(result.name).to.eql(custom_options.default.fields.name)
6868
expect(result._id).to.eql(custom_options.default.fields._id)
6969
expect(result.age).to.eql(1)

0 commit comments

Comments
 (0)