summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-17 09:46:30 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-17 09:46:30 +0000
commit4df965f4ed21353b6e0c89ac8286c64c6266ec04 (patch)
tree4b093162914c137315602548313be9d72cbac84d
parentf4d7a34c01256591004bc477c683868ef748f3bd (diff)
* file.c (rb_str_encode_ospath): when the encoding of the parameter
is ASCII-8BIT, should recognize as filesystem encoding, and convert to UTF-8 on Windows. * file.c (realpath_rec): should convert to ospath encoding before calling lstat(). * file.c (rb_realpath_internal): resolved string should take over the encoding of base string. * transcode.c (rb_str_encode): should return new string always. fixed #3444. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--file.c18
-rw-r--r--transcode.c7
3 files changed, 33 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 6680394a0a..926e5bba7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Thu Jun 17 18:37:47 2010 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * file.c (rb_str_encode_ospath): when the encoding of the parameter
+ is ASCII-8BIT, should recognize as filesystem encoding, and convert
+ to UTF-8 on Windows.
+
+ * file.c (realpath_rec): should convert to ospath encoding before
+ calling lstat().
+
+ * file.c (rb_realpath_internal): resolved string should take over
+ the encoding of base string.
+
+ * transcode.c (rb_str_encode): should return new string always.
+ fixed #3444.
+
Wed Jun 16 15:40:53 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* error.c (rb_bug): existence of _set_abort_behavior() depends on
diff --git a/file.c b/file.c
index 7bb4e0bdc5..5254c2255c 100644
--- a/file.c
+++ b/file.c
@@ -191,8 +191,11 @@ rb_str_encode_ospath(VALUE path)
if (enc != utf8)
path = rb_str_encode(path, rb_enc_from_encoding(utf8), 0, Qnil);
}
- else if (RSTRING_LEN(path) > 0)
- path = rb_str_encode(path, rb_enc_from_encoding(rb_filesystem_encoding()), 0, Qnil);
+ else if (RSTRING_LEN(path) > 0) {
+ path = rb_str_dup(path);
+ rb_enc_associate(path, rb_filesystem_encoding());
+ path = rb_str_encode(path, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil);
+ }
#endif
return path;
}
@@ -3223,7 +3226,8 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, char *unresolved, VALUE loopche
else {
struct stat sbuf;
int ret;
- ret = lstat(RSTRING_PTR(testpath), &sbuf);
+ VALUE testpath2 = rb_str_encode_ospath(testpath);
+ ret = lstat(RSTRING_PTR(testpath2), &sbuf);
if (ret == -1) {
if (errno == ENOENT) {
if (strict || !last || *unresolved_firstsep)
@@ -3292,7 +3296,8 @@ rb_realpath_internal(VALUE basedir, VALUE path, int strict)
ptr = RSTRING_PTR(unresolved_path);
path_names = skiproot(ptr);
if (ptr != path_names) {
- resolved = rb_str_new(ptr, path_names - ptr);
+ resolved = rb_enc_str_new(ptr, path_names - ptr,
+ rb_enc_get(unresolved_path));
goto root_found;
}
@@ -3300,7 +3305,8 @@ rb_realpath_internal(VALUE basedir, VALUE path, int strict)
ptr = RSTRING_PTR(basedir);
basedir_names = skiproot(ptr);
if (ptr != basedir_names) {
- resolved = rb_str_new(ptr, basedir_names - ptr);
+ resolved = rb_enc_str_new(ptr, basedir_names - ptr,
+ rb_enc_get(basedir));
goto root_found;
}
}
@@ -3308,7 +3314,7 @@ rb_realpath_internal(VALUE basedir, VALUE path, int strict)
curdir = rb_dir_getwd();
ptr = RSTRING_PTR(curdir);
curdir_names = skiproot(ptr);
- resolved = rb_str_new(ptr, curdir_names - ptr);
+ resolved = rb_enc_str_new(ptr, curdir_names - ptr, rb_enc_get(curdir));
root_found:
prefixptr = RSTRING_PTR(resolved);
diff --git a/transcode.c b/transcode.c
index adc72a19d7..dadb57b90d 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2805,7 +2805,12 @@ rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
int encidx = str_transcode0(argc, argv, &newstr, ecflags, ecopts);
if (encidx < 0) return rb_str_dup(str);
- RBASIC(newstr)->klass = rb_obj_class(str);
+ if (newstr == str) {
+ newstr = rb_str_dup(str);
+ }
+ else {
+ RBASIC(newstr)->klass = rb_obj_class(str);
+ }
return str_encode_associate(newstr, encidx);
}