summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 12:22:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 12:22:20 +0000
commitbf9c1d981889b23b97d45dcaf46cc9557cff93d4 (patch)
treef8af4c6a35a9bea854a1c1d35266497ccfc6ca81
parentc683096c90a0690f7e5c95f5e3e3f3e775bea08d (diff)
dir.c: check unknown keywords
* dir.c (dir_initialize): check unknown keywords. [ruby-dev:47152] [Bug #8060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--dir.c11
-rw-r--r--test/ruby/test_dir.rb7
3 files changed, 19 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 45b8977..343684c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Nov 30 21:22:11 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * dir.c (dir_initialize): check unknown keywords. [ruby-dev:47152]
+ [Bug #8060]
+
Sat Nov 30 18:05:38 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/win32ole/win32ole.c (hash2named_arg): correct declaration to fix
diff --git a/dir.c b/dir.c
index e3a74c1..99b1caa 100644
--- a/dir.c
+++ b/dir.c
@@ -424,17 +424,20 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
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);
}
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 0948ae7..7a46c07 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -200,6 +200,13 @@ class TestDir < Test::Unit::TestCase
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|