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

ruby-changes:37392

From: nagachika <ko1@a...>
Date: Mon, 2 Feb 2015 22:58:29 +0900 (JST)
Subject: [ruby-changes:37392] nagachika:r49473 (ruby_2_1): merge revision(s) r48360, r48364: [Backport #10493]

nagachika	2015-02-02 22:58:21 +0900 (Mon, 02 Feb 2015)

  New Revision: 49473

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

  Log:
    merge revision(s) r48360,r48364: [Backport #10493]
    
    * ext/etc/etc.c (etc_getlogin): set login name encoding properly.
      [ruby-core:66163] [Bug #10493]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/ext/etc/etc.c
    branches/ruby_2_1/test/etc/test_etc.rb
    branches/ruby_2_1/version.h
    branches/ruby_2_1/win32/win32.c
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 49472)
+++ ruby_2_1/ChangeLog	(revision 49473)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon Feb  2 22:57:30 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/etc/etc.c (etc_getlogin): set login name encoding properly.
+	  [ruby-core:66163] [Bug #10493]
+
 Mon Feb  2 22:47:35 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* proc.c (method_proc): the receiver of binding from method should
Index: ruby_2_1/win32/win32.c
===================================================================
--- ruby_2_1/win32/win32.c	(revision 49472)
+++ ruby_2_1/win32/win32.c	(revision 49473)
@@ -543,11 +543,15 @@ init_env(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/win32/win32.c#L543
 	if (!GetEnvironmentVariableW(L"USERNAME", env, numberof(env)) &&
 	    !GetUserNameW(env, (len = numberof(env), &len))) {
 	    NTLoginName = "<Unknown>";
-	    return;
 	}
-	set_env_val(L"USER");
+	else {
+	    set_env_val(L"USER");
+	    NTLoginName = rb_w32_wstr_to_mbstr(CP_UTF8, env, -1, NULL);
+	}
+    }
+    else {
+	NTLoginName = rb_w32_wstr_to_mbstr(CP_UTF8, env, -1, NULL);
     }
-    NTLoginName = strdup(rb_w32_getenv("USER"));
 
     if (!GetEnvironmentVariableW(TMPDIR, env, numberof(env)) &&
 	!GetEnvironmentVariableW(L"TMP", env, numberof(env)) &&
Index: ruby_2_1/ext/etc/etc.c
===================================================================
--- ruby_2_1/ext/etc/etc.c	(revision 49472)
+++ ruby_2_1/ext/etc/etc.c	(revision 49473)
@@ -67,8 +67,15 @@ etc_getlogin(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/etc/etc.c#L67
     login = getenv("USER");
 #endif
 
-    if (login)
-	return rb_tainted_str_new2(login);
+    if (login) {
+#ifdef _WIN32
+	rb_encoding *extenc = rb_utf8_encoding();
+#else
+	rb_encoding *extenc = rb_locale_encoding();
+#endif
+	return rb_external_str_new_with_enc(login, strlen(login), extenc);
+    }
+
     return Qnil;
 }
 
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 49472)
+++ ruby_2_1/version.h	(revision 49473)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.5"
 #define RUBY_RELEASE_DATE "2015-02-02"
-#define RUBY_PATCHLEVEL 289
+#define RUBY_PATCHLEVEL 290
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_1/test/etc/test_etc.rb
===================================================================
--- ruby_2_1/test/etc/test_etc.rb	(revision 49472)
+++ ruby_2_1/test/etc/test_etc.rb	(revision 49473)
@@ -4,7 +4,9 @@ require "etc" https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/etc/test_etc.rb#L4
 class TestEtc < Test::Unit::TestCase
   def test_getlogin
     s = Etc.getlogin
-    assert(s.is_a?(String) || s == nil, "getlogin must return a String or nil")
+    return if s == nil
+    assert(s.is_a?(String), "getlogin must return a String or nil")
+    assert_predicate(s, :valid_encoding?, "login name should be a valid string")
   end
 
   def test_passwd

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r48360,48364


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

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