From 5640f805d471b2da7f54fca7842f7e700154a9b6 Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Tue, 7 Dec 2010 08:47:56 +0000 Subject: [PATCH] Dir.glob: convert paths to unicode normalization form C git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4991 23306eb0-4c56-4727-a40e-e92c0eb68959 --- dir.c | 5 ++++- encoding.h | 2 ++ string.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 85e04c23c..409ccbd2c 100644 --- a/dir.c +++ b/dir.c @@ -15,6 +15,7 @@ #include "ruby/node.h" #include "ruby/util.h" #include "vm.h" +#include "encoding.h" #include #include @@ -1391,7 +1392,9 @@ rb_glob(const char *path, void (*func)(const char *, VALUE), VALUE arg) static void push_pattern(const char *path, VALUE ary) { - rb_ary_push(ary, rb_tainted_str_new2(path)); + VALUE str = rstr_new_path(path); + OBJ_TAINT(str); + rb_ary_push(ary, str); } int diff --git a/encoding.h b/encoding.h index f7ca2894f..f31a7a955 100644 --- a/encoding.h +++ b/encoding.h @@ -368,6 +368,8 @@ str_check_ascii_compatible(VALUE str) } } +VALUE rstr_new_path(const char *path); + #if defined(__cplusplus) } // extern "C" #endif diff --git a/string.c b/string.c index a1c11e248..869e7bfbb 100644 --- a/string.c +++ b/string.c @@ -6724,3 +6724,22 @@ rb_str_modify(VALUE obj) rb_raise(rb_eArgError, "can't modify NSString"); } } + +VALUE +rstr_new_path(const char *path) +{ + // XXX this should be rewritten using ICU (utrans.h?) to avoid creating + // these 2 temporary CFStrings. + CFStringRef tmp = CFStringCreateWithFileSystemRepresentation(NULL, path); + assert(tmp != NULL); + + CFMutableStringRef tmp2 = CFStringCreateMutableCopy(NULL, 0, tmp); + assert(tmp2 != NULL); + CFRelease(tmp); + CFStringNormalize(tmp2, kCFStringNormalizationFormC); + + rb_str_t *str = str_new_from_cfstring(tmp2); + CFRelease(tmp2); + + return (VALUE)str; +}