From 12dfd9d1c980d17d8a0ea10bccb9cd7eca21b568 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Mon, 25 Oct 2021 15:48:18 +0300 Subject: [flori/json] 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. https://github.com/flori/json/commit/cd8bbe56a3 --- test/json/json_generator_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb index f31b6b290e..b0f9a01759 100644 --- a/test/json/json_generator_test.rb +++ b/test/json/json_generator_test.rb @@ -391,6 +391,29 @@ EOT end end + if defined?(JSON::Ext::Generator) + def test_string_ext_included_calls_super + included = false + + Module.alias_method(:included_orig, :included) + Module.define_method(:included) do |base| + included_orig(base) + included = true + end + + Class.new(String) do + include JSON::Ext::Generator::GeneratorMethods::String + end + + assert included + ensure + if Module.private_method_defined?(:included_orig) + Module.alias_method(:included, :included_orig) + Module.remove_method(:included_orig) + end + end + end + if defined?(Encoding) def test_nonutf8_encoding assert_equal("\"5\u{b0}\"", "5\xb0".force_encoding("iso-8859-1").to_json) -- cgit v1.2.3