@@ -18,4 +18,48 @@ describe('JSONPath - Errors', function () {
1818 jsonpath ( { json : { book : [ ] } , path : '$..[?(@.category === category)]' } ) ;
1919 } ) . to . throw ( Error , 'jsonPath: category is not defined: _$_v.category === category' ) ;
2020 } ) ;
21+
22+ it ( 'should throw with a bad result type' , ( ) => {
23+ expect ( ( ) => {
24+ jsonpath ( {
25+ json : { children : [ 5 ] } ,
26+ path : '$..children' ,
27+ resultType : 'badType'
28+ } ) ;
29+ } ) . to . throw ( TypeError , 'Unknown result type' ) ;
30+ } ) ;
31+
32+ it ( 'should throw with `preventEval` and [?()] filtering expression' , ( ) => {
33+ expect ( ( ) => {
34+ const json = {
35+ datafield : [
36+ { "tag" : "035" , "subfield" : { "@code" : "a" , "#text" : "1879" } } ,
37+ { "@tag" : "042" , "subfield" : { "@code" : "a" , "#text" : "5555" } } ,
38+ { "@tag" : "045" , "045" : "secret" }
39+ ]
40+ } ;
41+ jsonpath ( {
42+ json,
43+ path : "$.datafield[?(@.tag=='035')]" ,
44+ preventEval : true
45+ } ) ;
46+ } ) . to . throw ( Error , 'Eval [?(expr)] prevented in JSONPath expression.' ) ;
47+ } ) ;
48+
49+ it ( 'should throw with `preventEval` and [?()] filtering expression' , ( ) => {
50+ expect ( ( ) => {
51+ const json = {
52+ datafield : [
53+ { "tag" : "035" , "subfield" : { "@code" : "a" , "#text" : "1879" } } ,
54+ { "@tag" : "042" , "subfield" : { "@code" : "a" , "#text" : "5555" } } ,
55+ { "@tag" : "045" , "045" : "secret" }
56+ ]
57+ } ;
58+ jsonpath ( {
59+ json,
60+ path : '$..datafield[(@.length-1)]' ,
61+ preventEval : true
62+ } ) ;
63+ } ) . to . throw ( Error , 'Eval [(expr)] prevented in JSONPath expression.' ) ;
64+ } ) ;
2165} ) ;
0 commit comments