Skip to content

Commit cd8bbe5

Browse files
committed
Call super in included hook
The C extension defines an `included` hook for the `JSON::Ext::Generator::GeneratorMethods::String` module but neglects to call `super` in the hook. This can break the functionality of various other code that rely on the fact that `included` on `Module` will always be called.
1 parent e3ed3eb commit cd8bbe5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ext/json/ext/generator/generator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
478478
*/
479479
static VALUE mString_included_s(VALUE self, VALUE modul) {
480480
VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend);
481+
rb_call_super(1, &modul);
481482
return result;
482483
}
483484

tests/json_generator_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,29 @@ def to_s; self; end
391391
end
392392
end
393393

394+
if defined?(JSON::Ext::Generator)
395+
def test_string_ext_included_calls_super
396+
included = false
397+
398+
Module.alias_method(:included_orig, :included)
399+
Module.define_method(:included) do |base|
400+
included_orig(base)
401+
included = true
402+
end
403+
404+
Class.new(String) do
405+
include JSON::Ext::Generator::GeneratorMethods::String
406+
end
407+
408+
assert included
409+
ensure
410+
if Module.private_method_defined?(:included_orig)
411+
Module.alias_method(:included, :included_orig)
412+
Module.remove_method(:included_orig)
413+
end
414+
end
415+
end
416+
394417
if defined?(Encoding)
395418
def test_nonutf8_encoding
396419
assert_equal("\"5\u{b0}\"", "5\xb0".force_encoding("iso-8859-1").to_json)

0 commit comments

Comments
 (0)