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

ruby-changes:31856

From: nobu <ko1@a...>
Date: Sat, 30 Nov 2013 21:22:27 +0900 (JST)
Subject: [ruby-changes:31856] nobu:r43935 (trunk): dir.c: check unknown keywords

nobu	2013-11-30 21:22:20 +0900 (Sat, 30 Nov 2013)

  New Revision: 43935

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

  Log:
    dir.c: check unknown keywords
    
    * dir.c (dir_initialize): check unknown keywords.  [ruby-dev:47152]
      [Bug #8060]

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/test/ruby/test_dir.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43934)
+++ ChangeLog	(revision 43935)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov 30 21:22:11 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (dir_initialize): check unknown keywords.  [ruby-dev:47152]
+	  [Bug #8060]
+
 Sat Nov 30 18:05:38 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/win32ole/win32ole.c (hash2named_arg): correct declaration to fix
Index: dir.c
===================================================================
--- dir.c	(revision 43934)
+++ dir.c	(revision 43935)
@@ -424,17 +424,20 @@ dir_initialize(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/dir.c#L424
     struct dir_data *dp;
     rb_encoding  *fsenc;
     VALUE dirname, opt, orig;
-    static VALUE sym_enc;
+    static ID keyword_ids[1];
 
-    if (!sym_enc) {
-	sym_enc = ID2SYM(rb_intern("encoding"));
+    if (!keyword_ids[0]) {
+	keyword_ids[0] = rb_intern("encoding");
     }
+
     fsenc = rb_filesystem_encoding();
 
     rb_scan_args(argc, argv, "1:", &dirname, &opt);
 
     if (!NIL_P(opt)) {
-	VALUE enc = rb_hash_aref(opt, sym_enc);
+	VALUE enc;
+	rb_check_keyword_opthash(opt, keyword_ids, 0, 1);
+	enc = rb_hash_aref(opt, ID2SYM(keyword_ids[0]));
 	if (!NIL_P(enc)) {
 	    fsenc = rb_to_encoding(enc);
 	}
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 43934)
+++ test/ruby/test_dir.rb	(revision 43935)
@@ -200,6 +200,13 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L200
     end
   end
 
+  def test_unknown_keywords
+    bug8060 = '[ruby-dev:47152] [Bug #8060]'
+    assert_raise_with_message(ArgumentError, /unknown keyword/, bug8060) do
+      Dir.open(@root, xawqij: "a") {}
+    end
+  end
+
   def test_symlink
     begin
       ["dummy", *?a..?z].each do |f|

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

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