From 823835499539aa53128a025ab72eb00c288dfb09 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 25 Mar 2023 11:07:09 +0900 Subject: merge revision(s) d6ce4180a5b4dacbac895c9911031a6df6c61136: [Backport #19243] Windows: Fix encoding of Dir.home Dir.home returns an UTF-8 string since ruby-3.0, but the actual encoding of the bytes was CP_ACP or CP_OEMCP. That led to invalid bytes when calling Dir.home with an unicode username. --- spec/ruby/core/dir/home_spec.rb | 11 +++++++++++ win32/file.c | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) --- spec/ruby/core/dir/home_spec.rb | 11 +++++++++++ version.h | 2 +- win32/file.c | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb index 713ba9db9a..e8c7f5970b 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -19,6 +19,17 @@ describe "Dir.home" do it "returns a non-frozen string" do Dir.home.should_not.frozen? end + + platform_is :windows do + ruby_version_is "3.0" do + it "returns the home directory with forward slashs and as UTF-8" do + ENV['HOME'] = "C:\\rubyspäc\\home" + home = Dir.home + home.should == "C:/rubyspäc/home" + home.encoding.should == Encoding::UTF_8 + end + end + end end describe "when called with the current user name" do diff --git a/version.h b/version.h index 6965efef46..01a9482ca2 100644 --- a/version.h +++ b/version.h @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 213 +#define RUBY_PATCHLEVEL 214 #define RUBY_RELEASE_YEAR 2023 #define RUBY_RELEASE_MONTH 3 diff --git a/win32/file.c b/win32/file.c index 33303823b6..561d7ca346 100644 --- a/win32/file.c +++ b/win32/file.c @@ -263,10 +263,12 @@ rb_default_home_dir(VALUE result) { WCHAR *dir = rb_w32_home_dir(); if (!dir) { - rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `~'"); + rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `~'"); } append_wstr(result, dir, -1, - rb_w32_filecp(), rb_filesystem_encoding()); + rb_w32_filecp(), rb_filesystem_encoding()); + CP_UTF8, rb_utf8_encoding()); + xfree(dir); return result; } -- cgit v1.2.3