Skip to content

Order of prepends and extends can break super #4531

@headius

Description

@headius

In debugging the behavior of CGI::Escape (a C ext added in Ruby 2.3) I discovered problems with the superclass logic surrounding prepended and extended modules.

Specifically, the following example will blow out the stack:

module X; end
class Foo; extend X; end
module Y; def blah; super; end; end
module X; prepend Y; end
class Foo; extend Y; end; Foo.blah

Small changes in order here will work properly, producing an error about "blah" not being available on Foo (for the super call).

For example, this works:

module Y; def blah; super; end; end
module X; prepend Y; end
class Foo; extend X; end
class Foo; extend Y; end; Foo.blah

For the moment I will modify the order in which these operations happen in the cgi library to get the related tests passing. Specifically, these fail:

test/ruby/cgi/test_cgi_util.rb

  Encoding.list.each do |enc|
    begin
      escaped = "'&"><".encode(enc)
      unescaped = "'&\"><".encode(enc)
    rescue Encoding::ConverterNotFoundError
      next
    else
      define_method("test_cgi_escapeHTML:#{enc.name}") do
        assert_equal(escaped, CGI::escapeHTML(unescaped))
      end
      define_method("test_cgi_unescapeHTML:#{enc.name}") do
        assert_equal(unescaped, CGI::unescapeHTML(escaped))
      end
    end
  end

Any non-ascii passed to these new optimized methods will hit the problem.

I believe this affects JRuby 9.1.8.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions