File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ const vm = JSONPath.nodeVMSupported
6464
6565 const funcString = funcs . reduce ( ( s , func ) => {
6666 let fString = context [ func ] . toString ( ) ;
67- if ( ! ( / f u n c t i o n / u) . exec ( fString ) ) {
67+ if ( ! ( / f u n c t i o n / u) . test ( fString ) ) {
6868 fString = 'function ' + fString ;
6969 }
7070 return 'var ' + func + '=' + fString + ';' + s ;
Original file line number Diff line number Diff line change @@ -60,6 +60,35 @@ checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
6060 assert . deepEqual ( result , expected ) ;
6161 } ) ;
6262
63+ it ( 'sandbox with function without "function" in string' , ( ) => {
64+ const expected = [ json . store . book ] ;
65+ const result = jsonpath ( {
66+ json,
67+ sandbox : {
68+ category ( ) {
69+ return 'reference' ;
70+ }
71+ } ,
72+ path : "$..[?(@.category === category())]" , wrap : false
73+ } ) ;
74+ assert . deepEqual ( result , expected ) ;
75+ } ) ;
76+
77+ it ( 'sandbox with function with "function" in string' , ( ) => {
78+ const expected = [ json . store . book ] ;
79+ const result = jsonpath ( {
80+ json,
81+ sandbox : {
82+ // eslint-disable-next-line object-shorthand
83+ category : function ( ) {
84+ return 'reference' ;
85+ }
86+ } ,
87+ path : "$..[?(@.category === category())]" , wrap : false
88+ } ) ;
89+ assert . deepEqual ( result , expected ) ;
90+ } ) ;
91+
6392 it ( 'sandbox (with parsing function)' , ( ) => {
6493 const expected = [ json . store . book ] ;
6594 const result = jsonpath ( {
You can’t perform that action at this time.
0 commit comments