1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

file.c: exception message encoding

* file.c (rb_file_expand_path_internal): preserve the file name
  encoding in an exception message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-07-24 08:38:01 +00:00
parent 9240eb3dfe
commit 1758ff0381
3 changed files with 23 additions and 3 deletions

View file

@ -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

8
file.c
View file

@ -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");

View file

@ -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) }