I am experimenting with the Rhino java engine, which I want to embed in a project of mine. I made a Scriptable object scope which defines the global functions print, printLine, log, logLine in JavaScript. I can pull all data printed and logged by these functions by calling pullOutput, which returns a pair of all printed Output and logged Output. I have tested these functions and everything works as expected, but one thing.
When I give as argument for my log functions a new line, the string doesn’t contain a new line char
but just “\n”. For example the following code:
Context context;
try {
context = Context.enter();
TemplateScope scope = TemplateScope.init(context);
context.evaluateString(scope, "log(\"test\" + \"\\n\");", "test source", 1, null);
Pair<String, String> result = scope.pullOutput();
System.out.println("log is: " + result.b);
} finally {
Context.exit();
}
gives:
out is:
log is: test\n
Which is obviously not what I am expecting.
The complete code is here:
Already fixed it. Another library overwrote my own rhino version with an old version and introduced this bug.