summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--file.c29
-rw-r--r--io.c21
3 files changed, 39 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c18ad9..623ba10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Nov 18 11:37:05 2009 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * io.c (rb_scan_open_args): move path encoding conversion
+ for filesystem encoding of Mac OS X.
+
+ * file.c (file_path_convert): added for convert encoding
+ of file path.
+
+ * file.c (rb_get_path_check): add file_path_convert.
+
Wed Nov 18 10:17:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_utf8_nth): no count_utf8_lead_bytes_with_word
diff --git a/file.c b/file.c
index 880523c..314ba82 100644
--- a/file.c
+++ b/file.c
@@ -103,6 +103,33 @@ VALUE rb_cStat;
#define insecure_obj_p(obj, level) (level >= 4 || (level > 0 && OBJ_TAINTED(obj)))
+VALUE
+file_path_convert(VALUE name)
+{
+ rb_encoding *fname_encoding = rb_enc_from_index(ENCODING_GET(name));
+ rb_encoding *fs_encoding = rb_filesystem_encoding();
+#ifdef __APPLE__
+ static rb_encoding *utf8mac_encoding;
+ if (!utf8mac_encoding)
+ utf8mac_encoding = rb_enc_find("UTF8-MAC");
+ if (rb_usascii_encoding() != fname_encoding
+ && rb_ascii8bit_encoding() != fname_encoding
+ && rb_utf8_encoding() != fname_encoding
+ && utf8mac_encoding != fname_encoding
+ && fs_encoding != fname_encoding) {
+ name = rb_str_conv_enc(name, fname_encoding, fs_encoding);
+ }
+#elif !defined(_WIN32)
+ if (rb_default_internal_encoding() != NULL
+ && rb_usascii_encoding() != fname_encoding
+ && rb_ascii8bit_encoding() != fname_encoding
+ && fs_encoding != fname_encoding) {
+ name = rb_str_conv_enc(name, fname_encoding, fs_encoding);
+ }
+#endif
+ return name;
+}
+
static VALUE
rb_get_path_check(VALUE obj, int level)
{
@@ -122,7 +149,9 @@ rb_get_path_check(VALUE obj, int level)
else {
tmp = obj;
}
+ StringValue(tmp);
exit:
+ tmp = file_path_convert(tmp);
StringValueCStr(tmp);
if (obj != tmp && insecure_obj_p(tmp, level)) {
rb_insecure_operation();
diff --git a/io.c b/io.c
index dc3a796..21188eb 100644
--- a/io.c
+++ b/io.c
@@ -5323,27 +5323,6 @@ rb_scan_open_args(int argc, VALUE *argv,
opt = pop_last_hash(&argc, argv);
rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
FilePathValue(fname);
-#ifdef __APPLE__
- {
- static rb_encoding *fs_encoding;
- static rb_encoding *utf8mac_encoding;
- rb_encoding *fname_encoding = rb_enc_get(fname);
- if (!fs_encoding)
- fs_encoding = rb_filesystem_encoding();
- if (!utf8mac_encoding)
- utf8mac_encoding = rb_enc_find("UTF8-MAC");
- if (rb_usascii_encoding() != fname_encoding
- && rb_ascii8bit_encoding() != fname_encoding
- && rb_utf8_encoding() != fname_encoding
- && utf8mac_encoding != fname_encoding
- && fs_encoding != fname_encoding) {
- static VALUE fs_enc;
- if (!fs_enc)
- fs_enc = rb_enc_from_encoding(fs_encoding);
- fname = rb_str_encode(fname, fs_enc, 0, Qnil);
- }
- }
-#endif
rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, convconfig_p);