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

ruby-changes:15022

From: nobu <ko1@a...>
Date: Sat, 13 Mar 2010 00:46:24 +0900 (JST)
Subject: [ruby-changes:15022] Ruby:r26897 (trunk): * file.c (rb_file_s_basename): check encoding of suffix.

nobu	2010-03-13 00:44:24 +0900 (Sat, 13 Mar 2010)

  New Revision: 26897

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

  Log:
    * file.c (rb_file_s_basename): check encoding of suffix.

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/test/ruby/test_file_exhaustive.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26896)
+++ ChangeLog	(revision 26897)
@@ -1,3 +1,7 @@
+Sat Mar 13 00:44:20 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_file_s_basename): check encoding of suffix.
+
 Sat Mar 13 00:11:05 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* ruby.c (ruby_init_loadpath_safe): mark initial load paths.
Index: test/ruby/test_file_exhaustive.rb
===================================================================
--- test/ruby/test_file_exhaustive.rb	(revision 26896)
+++ test/ruby/test_file_exhaustive.rb	(revision 26897)
@@ -423,6 +423,8 @@
     end
 
     assert_incompatible_encoding {|d| File.basename(d)}
+    assert_incompatible_encoding {|d| File.basename(d, ".*")}
+    assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}
   end
 
   def test_dirname
Index: file.c
===================================================================
--- file.c	(revision 26896)
+++ file.c	(revision 26897)
@@ -3324,9 +3324,15 @@
     long f, n;
 
     if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
+	rb_encoding *enc;
 	StringValue(fext);
+	if (!rb_enc_asciicompat(enc = rb_enc_get(fext))) {
+	    rb_raise(rb_eEncCompatError, "ascii incompatible character encodings: %s",
+		     rb_enc_name(enc));
+	}
     }
     FilePathStringValue(fname);
+    if (!NIL_P(fext)) rb_enc_check(fname, fext);
     if (RSTRING_LEN(fname) == 0 || !*(name = RSTRING_PTR(fname)))
 	return rb_str_new_shared(fname);
     name = skipprefix(name);

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

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