From: "thyresias (Thierry Lambert) via ruby-core" Date: 2025-09-04T09:21:04+00:00 Subject: [ruby-core:123175] [Ruby Bug#21561] Wrong encoding for File.dirname result on Windows Issue #21561 has been reported by thyresias (Thierry Lambert). ---------------------------------------- Bug #21561: Wrong encoding for File.dirname result on Windows https://bugs.ruby-lang.org/issues/21561 * Author: thyresias (Thierry Lambert) * Status: Open * ruby -v: ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [x64-mingw-ucrt] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I placed the file containing the code below in a directory named "�_signaler" to show the effect on non-ascii characters: ```ruby def dirname_encoding(file) h = { "file" => file, "File.dirname(file)" => File.dirname(file), "File.expand_path(file)" => File.expand_path(file), "File.expand_path(File.dirname(file))" => File.expand_path(File.dirname(file)), "File.dirname(File.expand_path(file))" => File.dirname(File.expand_path(file)), } puts h.each do |name, value| puts "#{name} = #{value.inspect} (#{value.encoding})" end end dirname_encoding "foo.bar" dirname_encoding "foo/bar" ``` The result: ``` file = "foo.bar" (UTF-8) File.dirname(file) = "." (US-ASCII) File.expand_path(file) = "D:/�_signaler/foo.bar" (UTF-8) File.expand_path(File.dirname(file)) = "D:/\xE0_signaler" (US-ASCII) File.dirname(File.expand_path(file)) = "D:/�_signaler" (UTF-8) file = "foo/bar" (UTF-8) File.dirname(file) = "foo" (UTF-8) File.expand_path(file) = "D:/�_signaler/foo/bar" (UTF-8) File.expand_path(File.dirname(file)) = "D:/�_signaler/foo" (UTF-8) File.dirname(File.expand_path(file)) = "D:/�_signaler/foo" (UTF-8) ``` The source problem is the encoding US-ASCII for "." This may be linked to Bug #20699. -- 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.ruby-lang.org/