Skip to content

Commit

Permalink
Merge pull request #486 from Shopify/uk-call-super-in-included
Browse files Browse the repository at this point in the history
Call `super` in `included` hook
  • Loading branch information
hsbt authored May 10, 2023
2 parents 248bc5b + cd8bbe5 commit a877630
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
*/
static VALUE mString_included_s(VALUE self, VALUE modul) {
VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend);
rb_call_super(1, &modul);
return result;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,29 @@ def to_s; self; end
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)
Expand Down

0 comments on commit a877630

Please sign in to comment.