Joints in heredoc in global function

I am having problems using beestings in heredoc in a global function. The runtime generates the error message " Exception: arg2 is not defined ". Here is an example:

 ruleset a163x59 { meta { name "Beesting in heredoc" description << Demonstrate the error with beestings in global function heredocs >> author "Steve Nay" logging on } dispatch { } global { myFunc = function(arg1, arg2) { firstString = "This is a regular string: #{arg1}. No problem there."; secondString = << This is a heredoc with a beesting: #{arg2}. Problem! >>; secondString; }; } rule first_rule { select when pageview ".*" setting () pre { msg = myFunc("First argument", "Second argument"); } notify("Testing...", msg) with sticky = true; } } 

He never complains about arg1 being undefined, which shows that using feeds inside the regular string is just fine.

Is there something I'm doing wrong or is this a mistake?

+4
source share
2 answers

This is actually a mistake, but there is a workaround. Replace the def function with this modified code:

 myFunc = function(arg1, arg2) { firstString = "This is a regular string: #{arg1}. No problem there."; secondString = << This is a heredoc with a beesting: #{arg2}. Problem! >>; "#{secondString}"; }; 

Note that the last statement (return value) is a quoted list. This forces you to allow any exits inside the heredoc, and it works.

The problem arises because KRL late binds beesting substitutions before javascript is executed, but there is an error in generating a closure, which leads to the fact that the variable is not available. Forcing permission with a cited list solves this problem.

+3
source

I confirmed in my tests that you really came across an error. I will send it and we will resolve it as soon as possible. Thanks.

+2
source

Source: https://habr.com/ru/post/1345304/


All Articles