File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ const builtInCasters = {
12
12
const parseValue = ( value , key , options ) => {
13
13
// Match type casting operators like string(true)
14
14
const casters = { ...builtInCasters , ...options . casters } ;
15
- const casting = value . match ( / ^ ( \w + ) \( ( .* ) \) $ / ) ;
15
+ const castersList = Object . keys ( casters ) . join ( '|' ) ;
16
+ const castersRegexp = new RegExp ( `^(${ castersList } )\\(([^)]*)\\)$` ) ;
17
+ const casting = value . match ( castersRegexp ) ;
16
18
if ( casting && casters [ casting [ 1 ] ] ) {
17
19
return casters [ casting [ 1 ] ] ( casting [ 2 ] ) ;
18
20
}
Original file line number Diff line number Diff line change @@ -185,12 +185,24 @@ test('filter: $in operator (multiple keys)', (t) => {
185
185
t . deepEqual ( res . filter , { key : { $in : [ 'a' , 'b' ] } } ) ;
186
186
} ) ;
187
187
188
+ test ( 'filter: $in operator (multiple keys), with casters' , ( t ) => {
189
+ const res = aqp ( 'key=string(1)&key=string(2)' ) ;
190
+ t . truthy ( res ) ;
191
+ t . deepEqual ( res . filter , { key : { $in : [ '1' , '2' ] } } ) ;
192
+ } ) ;
193
+
188
194
test ( 'filter: $in operator (comma-separated)' , ( t ) => {
189
195
const res = aqp ( 'key=a,b' ) ;
190
196
t . truthy ( res ) ;
191
197
t . deepEqual ( res . filter , { key : { $in : [ 'a' , 'b' ] } } ) ;
192
198
} ) ;
193
199
200
+ test ( 'filter: $in operator (comma-separated), with casters' , ( t ) => {
201
+ const res = aqp ( 'key=string(1),string(2)' ) ;
202
+ t . truthy ( res ) ;
203
+ t . deepEqual ( res . filter , { key : { $in : [ '1' , '2' ] } } ) ;
204
+ } ) ;
205
+
194
206
test ( 'filter: $in operator (comma-separated regexes)' , ( t ) => {
195
207
const res = aqp ( 'key=/a/,/b/' ) ;
196
208
t . truthy ( res ) ;
You can’t perform that action at this time.
0 commit comments