summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-24 18:02:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-24 18:02:31 +0000
commitc5255bdd03fd8edaaa0ed1584ef79a046a9be095 (patch)
tree64d53c035e14169d6a323112e974f66c0770e0d8 /hash.c
parent4f7449bebae380c2f60530d2b9a51a703f2f7cb6 (diff)
hash.c: env_str_transcode
* hash.c (env_str_transcode): convert with replacing invalid/undef characters, on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/hash.c b/hash.c
index 7c3ff98..8a4c8e5 100644
--- a/hash.c
+++ b/hash.c
@@ -2500,13 +2500,20 @@ extern char **environ;
#define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
#endif
+#ifdef _WIN32
+static VALUE
+env_str_transcode(VALUE str, rb_encoding *enc)
+{
+ return rb_str_conv_enc_opts(str, rb_utf8_encoding(), enc,
+ ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
+}
+#endif
+
static VALUE
env_str_new(const char *ptr, long len)
{
#ifdef _WIN32
- VALUE str = rb_str_conv_enc_opts(rb_str_new(ptr, len),
- rb_utf8_encoding(), rb_locale_encoding(),
- ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
+ VALUE str = env_str_transcode(rb_str_new(ptr, len), rb_locale_encoding());
#else
VALUE str = rb_locale_str_new(ptr, len);
#endif
@@ -2519,9 +2526,7 @@ static VALUE
env_path_str_new(const char *ptr)
{
#ifdef _WIN32
- VALUE str = rb_str_conv_enc_opts(rb_str_new_cstr(ptr),
- rb_utf8_encoding(), rb_filesystem_encoding(),
- ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
+ VALUE str = env_str_transcode(rb_str_new_cstr(ptr), rb_filesystem_encoding());
#else
VALUE str = rb_filesystem_str_new_cstr(ptr);
#endif