[前][次][番号順一覧][スレッド一覧]

ruby-changes:30361

From: nobu <ko1@a...>
Date: Thu, 8 Aug 2013 10:26:36 +0900 (JST)
Subject: [ruby-changes:30361] nobu:r42430 (trunk): file.c: rb_str_normalize_ospath

nobu	2013-08-08 10:26:27 +0900 (Thu, 08 Aug 2013)

  New Revision: 42430

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42430

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

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/file.c
_______________________________________________
ruby-cvs mailing list
ruby-cvs@r...
http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-cvs
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42429)
+++ ChangeLog	(revision 42430)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Aug  8 10:26:25 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_str_normalize_ospath): extract and move from dir.c.
+
 Thu Aug  8 05:59:00 2013  Charlie Somerville  <charliesome@r...>
 
 	* test/openssl/test_ssl.rb: Fix test for CVE-2013-4073.
Index: dir.c
===================================================================
--- dir.c	(revision 42429)
+++ dir.c	(revision 42430)
@@ -84,11 +84,7 @@ char *strchr(char*,char); https://github.com/ruby/ruby/blob/trunk/dir.c#L84
 #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) https://github.com/ruby/ruby/blob/trunk/dir.c#L630
 	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( https://github.com/ruby/ruby/blob/trunk/dir.c#L1421
 	    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);
 		}
 	    }
Index: file.c
===================================================================
--- file.c	(revision 42429)
+++ file.c	(revision 42430)
@@ -240,6 +240,19 @@ rb_str_encode_ospath(VALUE path) https://github.com/ruby/ruby/blob/trunk/file.c#L240
     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)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]