[ruby-core:123237] [Ruby Bug#21561] Wrong encoding for File.dirname result on Windows
From:
"k0kubun (Takashi Kokubun) via ruby-core" <ruby-core@...>
Date:
2025-09-12 21:58:20 UTC
List:
ruby-core #123237
Issue #21561 has been updated by k0kubun (Takashi Kokubun).
Backport changed from 3.2: WONTFIX, 3.3: REQUIRED, 3.4: REQUIRED to 3.2: WO=
NTFIX, 3.3: REQUIRED, 3.4: DONE
ruby_3_4 commit:21709a58682b9fef53e3e3dec97a0fe4498334e3 merged revision(s)=
commit:7a05dbc47831a655a1ef8a1635f88292acd325da.
----------------------------------------
Bug #21561: Wrong encoding for File.dirname result on Windows
https://bugs.ruby-lang.org/issues/21561#change-114568
* Author: thyresias (Thierry Lambert)
* Status: Closed
* ruby -v: ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [x64-mingw-uc=
rt]
* Backport: 3.2: WONTFIX, 3.3: REQUIRED, 3.4: DONE
----------------------------------------
I placed the file containing the code below in a directory named "=E0_signa=
ler" to show the effect on non-ascii characters:
```ruby
def dirname_encoding(file)
h =3D {
"file" =3D> file,
"File.dirname(file)" =3D> File.dirname(file),
"File.expand_path(file)" =3D> File.expand_path(file),
"File.expand_path(File.dirname(file))" =3D> File.expand_path(File.dirna=
me(file)),
"File.dirname(File.expand_path(file))" =3D> File.dirname(File.expand_pa=
th(file)),
}
puts
h.each do |name, value|
puts "#{name} =3D #{value.inspect} (#{value.encoding})"
end
end
dirname_encoding "foo.bar"
dirname_encoding "foo/bar"
```
The result:
```
file =3D "foo.bar" (UTF-8)
File.dirname(file) =3D "." (US-ASCII)
File.expand_path(file) =3D "D:/=E0_signaler/foo.bar" (UTF-8)
File.expand_path(File.dirname(file)) =3D "D:/\xE0_signaler" (US-ASCII)
File.dirname(File.expand_path(file)) =3D "D:/=E0_signaler" (UTF-8)
file =3D "foo/bar" (UTF-8)
File.dirname(file) =3D "foo" (UTF-8)
File.expand_path(file) =3D "D:/=E0_signaler/foo/bar" (UTF-8)
File.expand_path(File.dirname(file)) =3D "D:/=E0_signaler/foo" (UTF-8)
File.dirname(File.expand_path(file)) =3D "D:/=E0_signaler/foo" (UTF-8)
```
The source problem is the encoding US-ASCII for "."
This may be linked to Bug #20699.
--=20
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.rub=
y-lang.org/