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

ruby-changes:30098

From: nobu <ko1@a...>
Date: Wed, 24 Jul 2013 17:38:16 +0900 (JST)
Subject: [ruby-changes:30098] nobu:r42150 (trunk): file.c: exception message encoding

nobu	2013-07-24 17:38:01 +0900 (Wed, 24 Jul 2013)

  New Revision: 42150

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42150

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

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/test/ruby/test_file_exhaustive.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42149)
+++ ChangeLog	(revision 42150)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 24 17:37:50 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@a...>
 
 	* test/-ext-/tracepoint/test_tracepoint.rb: add GC on/off to count
Index: test/ruby/test_file_exhaustive.rb
===================================================================
--- test/ruby/test_file_exhaustive.rb	(revision 42149)
+++ test/ruby/test_file_exhaustive.rb	(revision 42150)
@@ -669,6 +669,19 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L669
     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) }
Index: file.c
===================================================================
--- file.c	(revision 42149)
+++ file.c	(revision 42150)
@@ -2909,7 +2909,7 @@ rb_home_dir(const char *user, VALUE resu https://github.com/ruby/ruby/blob/trunk/file.c#L2909
 	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 https://github.com/ruby/ruby/blob/trunk/file.c#L2991
 	    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");

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

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