@@ -339,6 +339,33 @@ describe('evaluateRuntimeExpressionPayload', () => {
339339 ) . toEqual ( '2023-12-15' ) ;
340340 } ) ;
341341
342+ it ( 'should not evaluate query-language strings as runtime expressions' , ( ) => {
343+ const payload = {
344+ jsonpath : "$.items[*].attributes[?(@.type=='foo')]" ,
345+ xpath : '$bookstore/book[price>35]/title' ,
346+ sparql : 'SELECT $item WHERE { $item <http://example.com/type> "foo" }' ,
347+ opa : 'data.items[_].type == "foo"' ,
348+ } ;
349+
350+ expect (
351+ evaluateRuntimeExpressionPayload ( { payload, context : runtimeExpressionContext , logger } )
352+ ) . toEqual ( payload ) ;
353+ } ) ;
354+
355+ it ( 'should evaluate {$faker.*} wrapped expression embedded in object payload' , ( ) => {
356+ const payload = { x : '{$faker.number.integer({ min: 5, max: 5 })}' } ;
357+ expect (
358+ evaluateRuntimeExpressionPayload ( { payload, context : runtimeExpressionContext , logger } )
359+ ) . toEqual ( { x : '5' } ) ;
360+ } ) ;
361+
362+ it ( 'should evaluate {$faker.*} wrapped expression mixed with surrounding text' , ( ) => {
363+ const payload = '{$faker.number.integer({ min: 5, max: 5 })} suffix' ;
364+ expect (
365+ evaluateRuntimeExpressionPayload ( { payload, context : runtimeExpressionContext , logger } )
366+ ) . toEqual ( '5 suffix' ) ;
367+ } ) ;
368+
342369 it ( 'should evaluate $faker runtime expression value' , ( ) => {
343370 const payload = '$faker.number.integer({ min: 1, max: 10 })' ;
344371 expect (
@@ -352,13 +379,13 @@ describe('evaluateRuntimeExpressionPayload', () => {
352379
353380 it ( 'should evaluate $faker inside string runtime expression value' , ( ) => {
354381 const payload = 'Some text {$faker.number.integer({ min: 1, max: 10 })}' ;
355- expect (
356- typeof evaluateRuntimeExpressionPayload ( {
357- payload ,
358- context : runtimeExpressionContext ,
359- logger ,
360- } )
361- ) . toBe ( 'string' ) ;
382+ const result = evaluateRuntimeExpressionPayload ( {
383+ payload ,
384+ context : runtimeExpressionContext ,
385+ logger ,
386+ } ) ;
387+ expect ( typeof result ) . toBe ( 'string' ) ;
388+ expect ( result ) . toMatch ( / ^ S o m e t e x t \d + $ / ) ;
362389 } ) ;
363390
364391 it ( 'should evaluate multiword runtime expression value' , ( ) => {
@@ -607,9 +634,9 @@ describe('evaluateRuntimeExpression', () => {
607634
608635 it ( 'should evaluate $faker inside string runtime expression value' , ( ) => {
609636 const payload = 'Some text {$faker.number.integer({ min: 1, max: 10 })}' ;
610- expect ( typeof evaluateRuntimeExpression ( payload , runtimeExpressionContext , logger ) ) . toBe (
611- 'string'
612- ) ;
637+ const result = evaluateRuntimeExpression ( payload , runtimeExpressionContext , logger ) ;
638+ expect ( typeof result ) . toBe ( 'string' ) ;
639+ expect ( result ) . toMatch ( / ^ S o m e t e x t \d + $ / ) ;
613640 } ) ;
614641
615642 it ( 'should evaluete list runtime expression value' , ( ) => {
0 commit comments