【问题标题】:In Rhino js, newlines don't get converted properly在 Rhino js 中,换行符没有正确转换
【发布时间】:2012-11-12 14:26:12
【问题描述】:

我正在试验 Rhino Java 引擎,我想将其嵌入到我的项目中。我创建了一个 Scriptable 对象范围,它在 JavaScript 中定义了全局函数 print, printLine, log, logLine。我可以通过调用pullOutput 来提取这些函数打印和记录的所有数据,它返回一对所有打印的输出和记录的输出。我已经测试了这些功能,一切都按预期工作,但有一件事。

当我为我的日志函数提供一个新行作为参数时,该字符串不包含一个新行字符 但只是“\ n”。比如下面的代码:

    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();
    }

给予:

    out is: 
    log is: test\n

这显然不是我所期望的。

完整代码在这里:

https://gist.github.com/4139978

【问题讨论】:

    标签: java javascript newline rhino


    【解决方案1】:

    已经修好了。另一个库用旧版本覆盖了我自己的 rhino 版本并引入了这个错误。

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      相关资源
      最近更新 更多