【问题标题】:SpiderMonkey and Unicode escapes: unexpected behaviorSpiderMonkey 和 Unicode 转义:意外行为
【发布时间】:2013-01-20 10:50:47
【问题描述】:

SpiderMonkey 是否正确处理 Unicode 转义?当我尝试使用 SpiderMonkey 将带有 unicode 转义符的字符串打印到标准输出时,它会处理它们。 V8 和 Node.JS 按预期显示输出。

这是蜘蛛猴:

$ js
js> this.print("\u201cquotes\u201d")
quotes

这比看起来更糟糕,因为输出包含无效 UTF-8 的二进制数据。

这里是 V8,它显示了引号:

$ v8
V8 version 3.7.0 [sample shell]
> this.print("\u201cquotes\u201d")
“quotes”

这里是 Node.JS,它也显示了引号:

$ node
> console.log("\u201cquotes\u201d")
“quotes”

编辑:我在 Mac OS X 10.8.2 (Mountain Lion) 上运行。

$ echo $LANG
en_US.UTF-8

$ js --version
JavaScript-C 1.8.5 2011-03-31

$ brew info spidermonkey
spidermonkey: stable 1.8.5, HEAD
https://developer.mozilla.org/en/SpiderMonkey
Depends on: readline, nspr
/usr/local/Cellar/spidermonkey/1.8.5 (101 files, 12M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/spidermonkey.rb
==> Caveats
This formula installs Spidermonkey 1.8.5.
If you are trying to compile MongoDB from scratch, you will need 1.7.x instead.

【问题讨论】:

    标签: javascript unicode spidermonkey


    【解决方案1】:

    您正在运行哪个版本?在我的机器上查看 mozilla-central 看起来不错。

    mozilla-central/js/dbg$ echo $LANG 
    en_US.UTF-8
    mozilla-central/js/dbg$ ./js -e 'this.print("\u201cquotes\u201d")'
    “quotes”
    mozilla-central/js/dbg$ hg log -l1 | head -n1
    changeset:   119130:8cc32d6fa707
    

    【讨论】:

    • 我正在运行版本 1.8.5,通过 Homebrew 安装在 OSX 上。问题已相应编辑
    • 我刚建了 119358:a97eb4f09112 并且成功了,所以应该是 1.8.5 之后修复的 bug。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 2021-12-26
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2014-09-25
    相关资源
    最近更新 更多