aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--file.c8
-rw-r--r--test/ruby/test_file_exhaustive.rb13
3 files changed, 23 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3879f5b51d..9169b5ab17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/file.c b/file.c
index 9eeacc67d6..2895669a50 100644
--- a/file.c
+++ b/file.c
@@ -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) }