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

ぐへぇ.簡単に再現するわ...

(ruby のインストールパス)/lib/ruby/2.7.0/pathname.rb を見てみたけど,特段バージョンの記述はないっぽい.どこ見ると分かるかしら.

ドキュメントによると FileTest ってモジュールに由来するメソッドっぽい.もっとコアに近いところにあるやつかしら.

class Pathname - pathname: Ruby Standard Library Documentation
ruby-doc.org/2.7.8/exts/pathna

そもそも ruby の File.stat にこの手のファイル名を渡してみるとファイルがないことを示す例外が起きる.

その線で調べて行ったら,ruby の win32.c 内で使われているWin の API である MultiByteToWideChar が失敗しているみたい(ワイド文字への変換ができていない).

zunda

@acid_rain 「𠮷」はUTF-16ではサロゲートペアになるのにどこかで配慮できていないのかな?と思ったのですが、MultiByteToWideChar関数じたいは少なくともVista以降なら問題なさそうですね:
https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibyte

Pathname#childrenがyieldしてくるオブジェクトのファイル名のエンコーディングが.file?の期待しているものと合っていないとか、うーん…

learn.microsoft.comMultiByteToWideChar function (stringapiset.h) - Win32 appsMaps a character string to a UTF-16 (wide character) string.

@acid_rain macOSですが、スクリプトのエンコーディングで結果が異なるようです。ファイルシステム難しい…

$ ls -1
main.rb
吉.txt
𠮷.txt
$ cat main.rb
require "pathname"
puts "ruby-#{RUBY_VERSION}, __ENCODING__:#{__ENCODING__}"
Pathname.new(".").children.each do |c|
puts "#{c}\t(#{c.to_s.encoding})\t#{c.file? ? "file" : "not file"}"
end
$ ruby main.rb
ruby-2.6.10, __ENCODING__:UTF-8
吉.txt (UTF-8) file
main.rb (UTF-8) file
𠮷.txt (UTF-8) file
$ ruby -Ks main.rb
ruby-2.6.10, __ENCODING__:Windows-31J
吉.txt (Windows-31J) file
main.rb (Windows-31J) file
𠮷.txt (Windows-31J) not file

@zundan 検証ありがとうございます.WinだとエンコーディングをUTF-8に指定しても同じ結果になってしまいますねぇ...難しい

@acid_rain うーん…ファイルシステム側が別のエンコーディングだったりするのかな…