oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

Dir.foreach should allow encoding #2627

Closed djberg96 closed 2 years ago

djberg96 commented 2 years ago

Ruby 3.0.2:

Dir.foreach(Dir.pwd, encoding: Encoding::UTF_16LE) do |f|
  p f.encoding # => #<Encoding:UTF-16LE>
end

Truffleruby 22.0.0.2:

wrong number of arguments (given 2, expected 1) (ArgumentError)

bjfish commented 2 years ago

This is now fixed at https://github.com/oracle/truffleruby/commit/199ad9507d6cd1192cab72028afd59590e74ab8a.

eregon commented 2 years ago

Note that this actually produces garbage entries:

$ ruby -e 'p Dir.foreach(Dir.pwd, encoding: Encoding::UTF_16LE) { |f| p f }'
"\x2E"
"\u2E2E"
"\u7073\u6365"
"\u494C\u4543\u434E\u2E45\u646D"
...

vs

$ ruby -e 'p Dir.foreach(Dir.pwd) { |f| p f }'          
"."
".."
"spec"
"LICENCE.md"
...

i.e., using the encoding there only makes sense if it's actually the encoding of the filesystem, and I think no filesystem uses UTF16. I need to change the spec for TruffleString, so I'll use another encoding.