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

ruby-changes:25154

From: nobu <ko1@a...>
Date: Tue, 16 Oct 2012 10:53:47 +0900 (JST)
Subject: [ruby-changes:25154] nobu:r37206 (trunk): file.c: check_path_encoding

nobu	2012-10-16 10:53:32 +0900 (Tue, 16 Oct 2012)

  New Revision: 37206

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

  Log:
    file.c: check_path_encoding
    
    * file.c (check_path_encoding): new function to ensure path name
      encoding to be ASCII-compatible.

  Modified files:
    trunk/ChangeLog
    trunk/file.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37205)
+++ ChangeLog	(revision 37206)
@@ -1,3 +1,8 @@
+Tue Oct 16 10:53:29 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (check_path_encoding): new function to ensure path name
+	  encoding to be ASCII-compatible.
+
 Tue Oct 16 09:40:04 2012  NAKAMURA Usaku  <usa@r...>
 
 	* test/ruby/test_regexp.rb
Index: file.c
===================================================================
--- file.c	(revision 37205)
+++ file.c	(revision 37206)
@@ -156,12 +156,22 @@
     return name;
 }
 
+static rb_encoding *
+check_path_encoding(VALUE str)
+{
+    rb_encoding *enc = rb_enc_get(str);
+    if (!rb_enc_asciicompat(enc)) {
+	rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %"PRIsVALUE,
+		 rb_enc_name(enc), rb_str_inspect(str));
+    }
+    return enc;
+}
+
 static VALUE
 rb_get_path_check(VALUE obj, int level)
 {
     VALUE tmp;
     ID to_path;
-    rb_encoding *enc;
 
     if (insecure_obj_p(obj, level)) {
 	rb_insecure_operation();
@@ -178,13 +188,8 @@
     if (obj != tmp && insecure_obj_p(tmp, level)) {
 	rb_insecure_operation();
     }
-    enc = rb_enc_get(tmp);
-    if (!rb_enc_asciicompat(enc)) {
-	tmp = rb_str_inspect(tmp);
-	rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %s",
-		 rb_enc_name(enc), RSTRING_PTR(tmp));
-    }
 
+    check_path_encoding(tmp);
     StringValueCStr(tmp);
 
     return rb_str_new4(tmp);
@@ -3669,11 +3674,7 @@
 
     if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
 	StringValue(fext);
-	enc = rb_enc_get(fext);
-	if (!rb_enc_asciicompat(enc)) {
-	    rb_raise(rb_eEncCompatError, "ascii incompatible character encodings: %s",
-		     rb_enc_name(enc));
-	}
+	enc = check_path_encoding(fext);
     }
     FilePathStringValue(fname);
     if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) {

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

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