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

ruby-changes:36553

From: usa <ko1@a...>
Date: Fri, 28 Nov 2014 16:30:30 +0900 (JST)
Subject: [ruby-changes:36553] usa:r48634 (ruby_2_0_0): merge revision(s) 48360, 48364: [Backport #10493]

usa	2014-11-28 16:30:21 +0900 (Fri, 28 Nov 2014)

  New Revision: 48634

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

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

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/ext/etc/etc.c
    branches/ruby_2_0_0/test/etc/test_etc.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/win32/win32.c
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 48633)
+++ ruby_2_0_0/ChangeLog	(revision 48634)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Fri Nov 28 16:28:07 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/etc/etc.c (etc_getlogin): set login name encoding properly.
+	  [ruby-core:66163] [Bug #10493]
+
 Fri Nov 28 16:18:44 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* proc.c (method_proc): the receiver of binding from method should
Index: ruby_2_0_0/win32/win32.c
===================================================================
--- ruby_2_0_0/win32/win32.c	(revision 48633)
+++ ruby_2_0_0/win32/win32.c	(revision 48634)
@@ -472,6 +472,16 @@ rb_w32_system_tmpdir(WCHAR *path, UINT l https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L472
     return p - path + numberof(temp) - 1;
 }
 
+static UINT filecp(void);
+static WCHAR *mbstr_to_wstr(UINT, const char *, int, long *);
+static char *wstr_to_mbstr(UINT, const WCHAR *, int, long *);
+#define acp_to_wstr(str, plen) mbstr_to_wstr(CP_ACP, str, -1, plen)
+#define wstr_to_acp(str, plen) wstr_to_mbstr(CP_ACP, str, -1, plen)
+#define filecp_to_wstr(str, plen) mbstr_to_wstr(filecp(), str, -1, plen)
+#define wstr_to_filecp(str, plen) wstr_to_mbstr(filecp(), str, -1, plen)
+#define utf8_to_wstr(str, plen) mbstr_to_wstr(CP_UTF8, str, -1, plen)
+#define wstr_to_utf8(str, plen) wstr_to_mbstr(CP_UTF8, str, -1, plen)
+
 /* License: Ruby's */
 static void
 init_env(void)
@@ -518,11 +528,15 @@ init_env(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L528
 	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 = wstr_to_mbstr(CP_UTF8, env, -1, NULL);
+	}
+    }
+    else {
+	NTLoginName = 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)) &&
@@ -1165,16 +1179,6 @@ is_batch(const char *cmd) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L1179
     return 0;
 }
 
-static UINT filecp(void);
-static WCHAR *mbstr_to_wstr(UINT, const char *, int, long *);
-static char *wstr_to_mbstr(UINT, const WCHAR *, int, long *);
-#define acp_to_wstr(str, plen) mbstr_to_wstr(CP_ACP, str, -1, plen)
-#define wstr_to_acp(str, plen) wstr_to_mbstr(CP_ACP, str, -1, plen)
-#define filecp_to_wstr(str, plen) mbstr_to_wstr(filecp(), str, -1, plen)
-#define wstr_to_filecp(str, plen) wstr_to_mbstr(filecp(), str, -1, plen)
-#define utf8_to_wstr(str, plen) mbstr_to_wstr(CP_UTF8, str, -1, plen)
-#define wstr_to_utf8(str, plen) wstr_to_mbstr(CP_UTF8, str, -1, plen)
-
 /* License: Artistic or GPL */
 rb_pid_t
 rb_w32_spawn(int mode, const char *cmd, const char *prog)
Index: ruby_2_0_0/ext/etc/etc.c
===================================================================
--- ruby_2_0_0/ext/etc/etc.c	(revision 48633)
+++ ruby_2_0_0/ext/etc/etc.c	(revision 48634)
@@ -68,8 +68,15 @@ etc_getlogin(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/etc/etc.c#L68
     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_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 48633)
+++ ruby_2_0_0/version.h	(revision 48634)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-11-28"
-#define RUBY_PATCHLEVEL 603
+#define RUBY_PATCHLEVEL 604
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 11
Index: ruby_2_0_0/test/etc/test_etc.rb
===================================================================
--- ruby_2_0_0/test/etc/test_etc.rb	(revision 48633)
+++ ruby_2_0_0/test/etc/test_etc.rb	(revision 48634)
@@ -4,7 +4,9 @@ require "etc" https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/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_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r48360,48364


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

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