mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 48360,48364: [Backport #10493]
* ext/etc/etc.c (etc_getlogin): set login name encoding properly. [ruby-core:66163] [Bug #10493] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@48634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7149859bc3
commit
bcafeef2e7
5 changed files with 35 additions and 17 deletions
|
|
@ -1,3 +1,8 @@
|
|||
Fri Nov 28 16:28:07 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* proc.c (method_proc): the receiver of binding from method should
|
||||
|
|
|
|||
|
|
@ -68,8 +68,15 @@ etc_getlogin(VALUE obj)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ require "etc"
|
|||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#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
|
||||
|
|
|
|||
|
|
@ -472,6 +472,16 @@ rb_w32_system_tmpdir(WCHAR *path, UINT len)
|
|||
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)
|
|||
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)
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue