Actions
Bug #17517
closedFile.expand_path returns us-ascii when both arguments are ascii compat
Description
Is this intentional?
p __dir__.encoding #=> #<Encoding:UTF-8>
p 'hoge'.encoding #=> #<Encoding:UTF-8>
p File.expand_path('hoge', __dir__).encoding #=> #<Encoding:US-ASCII>
% docker run -it --rm ghcr.io/ruby/all-ruby env ALL_RUBY_SINCE=ruby-1.9 ./all-ruby -e 'p File.expand_path("hoge".encode("utf-8"), "/".encode("utf-8")).encoding'
ruby-1.9.0-0 -e:1:in `encode': transcoding not supported (from ASCII-8BIT to UTF-8) (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-1.9.0-1 #<Encoding:ASCII-8BIT>
ruby-1.9.0-2 #<Encoding:US-ASCII>
...
ruby-1.9.1-p129 #<Encoding:US-ASCII>
ruby-1.9.1-p243 #<Encoding:UTF-8>
...
ruby-1.9.2-preview1 #<Encoding:UTF-8>
ruby-1.9.2-preview3 #<Encoding:US-ASCII>
...
ruby-3.0.0 #<Encoding:US-ASCII>
Updated by byroot (Jean Boussier) almost 4 years ago
I'm pretty sure it is intentional. That function calls rb_filesystem_encoding
https://github.com/ruby/ruby/blob/d968829afa19c31e9461fd545cbd21250778ce6e/file.c#L3696
Updated by duerst (Martin Dürst) almost 4 years ago
- Subject changed from File.expand_path returns us-aascii when both arguments are ascii compat to File.expand_path returns us-ascii when both arguments are ascii compat
Fix a typo in subject.
Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago
Original question is __FILE__
and __dir__
are us-ascii only when loaded by relative_require
.
% cat hoge.rb
p __FILE__.encoding
p __dir__.encoding
% cat require_relative.rb
require_relative 'hoge'
% ruby require_relative.rb
#<Encoding:US-ASCII>
#<Encoding:US-ASCII>
% cat require.rb
require './hoge'
% ruby require.rb
#<Encoding:UTF-8>
#<Encoding:UTF-8>
Updated by nobu (Nobuyoshi Nakada) almost 4 years ago
Updated by nobu (Nobuyoshi Nakada) almost 4 years ago
- Status changed from Open to Closed
Applied in changeset git|0d57d59933fb7b826bd0e20d84ed7f6d6636ac90.
Keep encoding in the result of File.expand_path [Bug #17517]
Actions
Like0
Like0Like0Like0Like0Like0