mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

本当は怖いUTF-16

$ irb
> "𠮷".encode("UTF-8").length
=> 1
> "𠮷".encode("UTF-16").length
=> 2

zunda

端末はUTF-8なんだけどnodeがUTF-16に変換してるのかしら

$ node
> "𠮷".length
2

むっちゃ能動的にUTF-8を受け取ってるのかもしれない

$ echo 'console.log("𠮷".length)' | iconv -f utf-8 -t utf-8 | node
2
$ echo 'console.log("𠮷".length)' | iconv -f utf-8 -t utf-16 | node
[stdin]:1
��c

SyntaxError: Invalid or unexpected token
at new Script (node:vm:93:7)
at createScript (node:vm:248:10)
at Object.runInThisContext (node:vm:296:10)
at node:internal/process/execution:83:21
at [stdin]-wrapper:6:24
at runScript (node:internal/process/execution:82:62)
at evalScript (node:internal/process/execution:104:10)
at node:internal/main/eval_stdin:31:5
at Socket.<anonymous> (node:internal/process/execution:205:5)
at Socket.emit (node:events:526:35)

Node.js v20.8.0

@omasanori はい。素朴に、nodeはUTF-8の文字列(1文字だけれど)をわけのわからないバイト列として受け取ってそうだと想像したのですが、ちゃんとUTF-16として受け取っていました。

@zundan それも能動的に(寒)