diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | file.c | 8 | ||||
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 13 |
3 files changed, 23 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Wed Jul 24 17:37:50 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * file.c (rb_file_expand_path_internal): preserve the file name + encoding in an exception message. + Wed Jul 24 08:04:49 2013 Koichi Sasada <ko1@atdot.net> * test/-ext-/tracepoint/test_tracepoint.rb: add GC on/off to count @@ -2909,7 +2909,7 @@ rb_home_dir(const char *user, VALUE result) struct passwd *pwPtr = getpwnam(user); if (!pwPtr) { endpwent(); - rb_raise(rb_eArgError, "user %s doesn't exist", user); + return Qnil; } dirlen = strlen(pwPtr->pw_dir); rb_str_resize(result, dirlen); @@ -2991,11 +2991,13 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na p += userlen; } if (NIL_P(rb_home_dir(buf, result))) { - rb_raise(rb_eArgError, "can't find user %s", buf); + rb_enc_raise(enc, rb_eArgError, "%.0"PRIsVALUE"user %s doesn't exist", fname, + buf); } if (!rb_is_absolute_path(RSTRING_PTR(result))) { if (userlen) { - rb_raise(rb_eArgError, "non-absolute home of %.*s", (int)userlen, b); + rb_enc_raise(enc, rb_eArgError, "non-absolute home of %.*s%.0"PRIsVALUE, + (int)userlen, b, fname); } else { rb_raise(rb_eArgError, "non-absolute home"); diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 3394d12372..219d357cf2 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -669,6 +669,19 @@ class TestFileExhaustive < Test::Unit::TestCase assert_raise(ArgumentError, bug) { File.expand_path("~anything") } end if DRIVE + def test_expand_path_error_for_nonexistent_username + user = "\u{3086 3046 3066 3044}:\u{307F 3084 304A 3046}" + assert_raise_with_message(ArgumentError, /#{user}/) {File.expand_path("~#{user}")} + end unless DRIVE + + def test_expand_path_error_for_non_absolute_home + old_home = ENV["HOME"] + ENV["HOME"] = "./UserHome" + assert_raise_with_message(ArgumentError, /non-absolute home/) {File.expand_path("~")} + ensure + ENV["HOME"] = old_home + end + def test_expand_path_raises_a_type_error_if_not_passed_a_string_type assert_raise(TypeError) { File.expand_path(1) } assert_raise(TypeError) { File.expand_path(nil) } |