我在全局函数中使用heredoc中的beestings时遇到了麻烦。运行时抛出错误“Exception: arg2 is not defined
”。这是一个例子:
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;
}
}
它永远不会抱怨arg1
未定义,这表明在常规字符串中使用beest是正常的。
我有什么问题,或者这是一个错误吗?
答案 0 :(得分:3)
这实际上是一个错误,但有一个解决方法。用这个修改过的代码替换你的函数def:
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}";
};
请注意,最后一个语句(返回值)是引用的beesting。这迫使解决了heredoc中的任何beestings,并且它有效。
问题出现是因为KRL后来绑定了beesting替换,直到javascript执行,但是闭包生成中存在一个错误导致变量不可用。使用引用的beesting强制解决这个问题。
答案 1 :(得分:2)
我已经在自己的测试中证实你确实偶然发现了一个错误。我会收到它,我们会尽快解决。谢谢。