1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

file.c: rb_str_normalize_ospath

* file.c (rb_str_normalize_ospath): extract and move from dir.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-08-08 01:26:27 +00:00
parent 885147037b
commit 354028abe1
3 changed files with 21 additions and 13 deletions

View file

@ -1,3 +1,7 @@
Thu Aug 8 10:26:25 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_str_normalize_ospath): extract and move from dir.c.
Thu Aug 8 05:59:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
* test/openssl/test_ssl.rb: Fix test for CVE-2013-4073.

17
dir.c
View file

@ -84,11 +84,7 @@ char *strchr(char*,char);
#include <sys/param.h>
#include <sys/mount.h>
rb_encoding *
rb_utf8mac_encoding(void)
{
return rb_enc_from_index(ENCINDEX_UTF8_MAC);
}
VALUE rb_str_normalize_ospath(const char *ptr, long len);
static inline int
is_hfs(DIR *dirp)
@ -634,10 +630,8 @@ dir_each(VALUE dir)
VALUE path;
#if HAVE_HFS
VALUE utf8str = Qnil;
rb_encoding *utf8mac = 0;
if (hfs_p && has_nonascii(name, namlen) && (utf8mac = rb_utf8mac_encoding()) != 0) {
utf8str = rb_str_conv_enc(rb_tainted_str_new(name, namlen),
utf8mac, rb_utf8_encoding());
if (hfs_p && has_nonascii(name, namlen) &&
!NIL_P(utf8str = rb_str_normalize_ospath(name, namlen))) {
RSTRING_GETMEM(utf8str, name, namlen);
}
#endif
@ -1427,10 +1421,7 @@ glob_helper(
namlen = NAMLEN(dp);
# if HAVE_HFS
if (hfs_p && has_nonascii(name, namlen)) {
rb_encoding *utf8mac = rb_utf8mac_encoding();
if (utf8mac) {
utf8str = rb_str_conv_enc(rb_str_new(name, namlen),
utf8mac, rb_utf8_encoding());
if (!NIL_P(utf8str = rb_str_normalize_ospath(name, namlen))) {
RSTRING_GETMEM(utf8str, name, namlen);
}
}

13
file.c
View file

@ -240,6 +240,19 @@ rb_str_encode_ospath(VALUE path)
return path;
}
#ifdef __APPLE__
VALUE
rb_str_normalize_ospath(const char *ptr, long len)
{
rb_encoding *utf8mac = rb_enc_from_index(ENCINDEX_UTF8_MAC);
if (utf8mac) {
return rb_str_conv_enc(rb_tainted_str_new(ptr, len),
utf8mac, rb_utf8_encoding());
}
return Qnil;
}
#endif
static long
apply2files(void (*func)(const char *, VALUE, void *), VALUE vargs, void *arg)
{