[前][次][番号順一覧][スレッド一覧]

ruby-changes:60793

From: Nobuyoshi <ko1@a...>
Date: Thu, 16 Apr 2020 23:40:37 +0900 (JST)
Subject: [ruby-changes:60793] fedc8075fe (master): Preserve encoding in error messages for invalid user/group name

https://git.ruby-lang.org/ruby.git/commit/?id=fedc8075fe

From fedc8075fe2a2bbbfa12c028c0879330d7db5596 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 16 Apr 2020 20:40:53 +0900
Subject: Preserve encoding in error messages for invalid user/group name


diff --git a/process.c b/process.c
index 129a2e6..efe9984 100644
--- a/process.c
+++ b/process.c
@@ -5585,7 +5585,7 @@ obj2uid(VALUE id https://github.com/ruby/ruby/blob/trunk/process.c#L5585
 #ifndef USE_GETPWNAM_R
 	    endpwent();
 #endif
-	    rb_raise(rb_eArgError, "can't find user for %s", usrname);
+            rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, id);
 	}
 	uid = pwptr->pw_uid;
 #ifndef USE_GETPWNAM_R
@@ -5664,7 +5664,7 @@ obj2gid(VALUE id https://github.com/ruby/ruby/blob/trunk/process.c#L5664
 #if !defined(USE_GETGRNAM_R) && defined(HAVE_ENDGRENT)
 	    endgrent();
 #endif
-	    rb_raise(rb_eArgError, "can't find group for %s", grpname);
+            rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, id);
 	}
 	gid = grptr->gr_gid;
 #if !defined(USE_GETGRNAM_R) && defined(HAVE_ENDGRENT)
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index ccca183..e8367b7 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1610,6 +1610,9 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1610
       if u = Etc.getpwuid(Process.uid)
         assert_equal(Process.uid, Process::UID.from_name(u.name), u.name)
       end
+      assert_raise_with_message(ArgumentError, /\u{4e0d 5b58 5728}/) {
+        Process::UID.from_name("\u{4e0d 5b58 5728}")
+      }
     end
   end
 
@@ -1618,6 +1621,9 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1621
       if g = Etc.getgrgid(Process.gid)
         assert_equal(Process.gid, Process::GID.from_name(g.name), g.name)
       end
+      assert_raise_with_message(ArgumentError, /\u{4e0d 5b58 5728}/) {
+        Process::GID.from_name("\u{4e0d 5b58 5728}")
+      }
     end
   end
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]