summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-16 20:40:53 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-16 20:50:08 +0900
commitfedc8075fe2a2bbbfa12c028c0879330d7db5596 (patch)
treeba8ff4aedc2c73cb5b4d646937d8a574412053a4
parent748c7c7c0b4ce605c0cedf971e94f0076e0e77de (diff)
Preserve encoding in error messages for invalid user/group name
-rw-r--r--process.c4
-rw-r--r--test/ruby/test_process.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/process.c b/process.c
index 129a2e6706..efe9984348 100644
--- a/process.c
+++ b/process.c
@@ -5585,7 +5585,7 @@ obj2uid(VALUE id
#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
#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 ccca1834cf..e8367b7201 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1610,6 +1610,9 @@ class TestProcess < Test::Unit::TestCase
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
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