summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-27 10:41:16 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-27 10:41:16 +0000
commited8c211a645cfb0528128306789d73441afadf31 (patch)
tree5c2fbd9fcb1fd3aaa9aecc98263ebd1bd26b888d
parent3aed194ac3edba9249b34fce09de36fa76326cbc (diff)
merge revision(s) 56980,56981: [Backport #13004]
extension.rdoc: fix rb_get_kwargs [ci skip] * doc/extension.rdoc: [DOC] optional keyword arguments are defaulted to Qundef. ignored keys are kept in the hash but a new Hash is not created. [ruby-dev:49893] [Bug #13004] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@57215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--README.EXT7
-rw-r--r--README.EXT.ja8
-rw-r--r--class.c2
-rw-r--r--test/ruby/test_keyword.rb7
-rw-r--r--version.h2
6 files changed, 26 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 960e8cd7d4..68aca35b79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Dec 27 19:40:09 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * README.EXT{.ja,}: [DOC] optional keyword arguments are defaulted to
+ Qundef. ignored keys are kept in the hash but a new Hash is not
+ created. [Bug #13004]
+
+ * class.c (rb_get_kwargs): when values are stored, corresponding keys
+ have been remove from the keyword hash, and the hash should be empty
+ in that case. [Bug #13004]
+
Tue Dec 27 19:34:47 2016 Aaron Patterson <tenderlove@ruby-lang.org>
* variable.c (rb_ivar_count): stop reading past the end of ivptr array.
diff --git a/README.EXT b/README.EXT
index 3e010c3002..29cfbc27e9 100644
--- a/README.EXT
+++ b/README.EXT
@@ -1314,10 +1314,9 @@ int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optiona
+optional+ is negative) number of IDs are optional. If a
mandatory key is not contained in +keyword_hash+, raises "missing
keyword" +ArgumentError+. If an optional key is not present in
- +keyword_hash+, the corresponding element in +values+ is not changed.
- If +optional+ is negative, rest of +keyword_hash+ are stored in the
- next to optional +values+ as a new Hash, otherwise raises "unknown
- keyword" +ArgumentError+.
+ +keyword_hash+, the corresponding element in +values+ is set to +Qundef+.
+ If +optional+ is negative, rest of +keyword_hash+ are ignored, otherwise
+ raises "unknown keyword" +ArgumentError+.
VALUE rb_extract_keywords(VALUE *original_hash)
diff --git a/README.EXT.ja b/README.EXT.ja
index b662d4dfdb..2a3fd69b9d 100644
--- a/README.EXT.ja
+++ b/README.EXT.ja
@@ -1315,10 +1315,10 @@ int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optiona
optional (optionalが負の場合は-optional-1) 個のIDは省略可能
キーワードです.必須キーワードがkeyword_hash中にない場合,
"missing keyword"ArgumentErrorが発生します.省略可能キーワー
- ドがない場合は,values中の対応する要素は変更されません.
- keyword_hashに使用されない要素がある場合は,optionalが負なら
- 新しいHashとして省略可能引数の次に保存されますが,そうでなけ
- れば"unknown keyword"ArgumentErrorが発生します.
+ ドがない場合は,values中の対応する要素にはQundefがセットされ
+ ます.keyword_hashに使用されない要素がある場合は,optionalが
+ 負なら無視されますが,そうでなければ"unknown keyword"
+ ArgumentErrorが発生します.
VALUE rb_extract_keywords(VALUE *original_hash)
diff --git a/class.c b/class.c
index f142f4472a..13ab80dcd0 100644
--- a/class.c
+++ b/class.c
@@ -1969,7 +1969,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
}
}
if (!rest && keyword_hash) {
- if (RHASH_SIZE(keyword_hash) > (unsigned int)j) {
+ if (RHASH_SIZE(keyword_hash) > (unsigned int)(values ? 0 : j)) {
unknown_keyword_error(keyword_hash, table, required+optional);
}
}
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 764bd959b1..82037575f9 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -540,6 +540,13 @@ class TestKeywordArguments < Test::Unit::TestCase
}
end
+ def test_unknown_keyword
+ bug13004 = '[ruby-dev:49893] [Bug #13004]'
+ assert_raise_with_message(ArgumentError, /unknown keyword: invalid-argument/, bug13004) {
+ [].sample(random: nil, "invalid-argument": nil)
+ }
+ end
+
def test_super_with_anon_restkeywords
bug10659 = '[ruby-core:67157] [Bug #10659]'
diff --git a/version.h b/version.h
index b090b5c7f3..0a35fc4456 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.7"
#define RUBY_RELEASE_DATE "2016-12-27"
-#define RUBY_PATCHLEVEL 405
+#define RUBY_PATCHLEVEL 406
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 12