Skip to content

Commit

Permalink
Dir.glob: convert paths to unicode normalization form C
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4991 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Dec 7, 2010
1 parent b452bea commit 5640f80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dir.c
Expand Up @@ -15,6 +15,7 @@
#include "ruby/node.h" #include "ruby/node.h"
#include "ruby/util.h" #include "ruby/util.h"
#include "vm.h" #include "vm.h"
#include "encoding.h"


#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
Expand Down Expand Up @@ -1391,7 +1392,9 @@ rb_glob(const char *path, void (*func)(const char *, VALUE), VALUE arg)
static void static void
push_pattern(const char *path, VALUE ary) 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 int
Expand Down
2 changes: 2 additions & 0 deletions encoding.h
Expand Up @@ -368,6 +368,8 @@ str_check_ascii_compatible(VALUE str)
} }
} }


VALUE rstr_new_path(const char *path);

#if defined(__cplusplus) #if defined(__cplusplus)
} // extern "C" } // extern "C"
#endif #endif
Expand Down
19 changes: 19 additions & 0 deletions string.c
Expand Up @@ -6724,3 +6724,22 @@ rb_str_modify(VALUE obj)
rb_raise(rb_eArgError, "can't modify NSString"); 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;
}

0 comments on commit 5640f80

Please sign in to comment.