diff --git a/core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java b/core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java index 54a0a0d08e6..06b6acb68cd 100644 --- a/core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java +++ b/core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java @@ -346,14 +346,14 @@ static IRubyObject optimized_escape(Ruby runtime, RubyString str) { * Returns HTML-escaped string. * */ - @JRubyMethod(name = "escapeHTML", module = true) + @JRubyMethod(name = "escapeHTML", module = true, frame = true) public static IRubyObject cgiesc_escape_html(ThreadContext context, IRubyObject self, IRubyObject _str) { RubyString str = _str.convertToString(); if (str.getEncoding().isAsciiCompatible()) { return optimized_escape_html(context.runtime, str); } else { - return Helpers.invokeSuper(context, self, self.getMetaClass(), "escapeHTML", _str, Block.NULL_BLOCK); + return Helpers.invokeSuper(context, self, _str, Block.NULL_BLOCK); } } @@ -364,14 +364,14 @@ public static IRubyObject cgiesc_escape_html(ThreadContext context, IRubyObject * Returns HTML-unescaped string. * */ - @JRubyMethod(name = "unescapeHTML", module = true) + @JRubyMethod(name = "unescapeHTML", module = true, frame = true) public static IRubyObject cgiesc_unescape_html(ThreadContext context, IRubyObject self, IRubyObject _str) { RubyString str = _str.convertToString(); if (str.getEncoding().isAsciiCompatible()) { return optimized_unescape_html(context.runtime, str); } else { - return Helpers.invokeSuper(context, self, self.getMetaClass(), "unescapeHTML", _str, Block.NULL_BLOCK); + return Helpers.invokeSuper(context, self, _str, Block.NULL_BLOCK); } } @@ -382,14 +382,14 @@ public static IRubyObject cgiesc_unescape_html(ThreadContext context, IRubyObjec * Returns URL-escaped string. * */ - @JRubyMethod(name = "escape", module = true) + @JRubyMethod(name = "escape", module = true, frame = true) public static IRubyObject cgiesc_escape(ThreadContext context, IRubyObject self, IRubyObject _str) { RubyString str = _str.convertToString(); if (str.getEncoding().isAsciiCompatible()) { return optimized_escape(context.runtime, str); } else { - return Helpers.invokeSuper(context, self, self.getMetaClass(), "escape", _str, Block.NULL_BLOCK); + return Helpers.invokeSuper(context, self, _str, Block.NULL_BLOCK); } } @@ -406,7 +406,7 @@ static IRubyObject accept_charset(IRubyObject[] args, int argc, int argv, IRubyO * Returns URL-unescaped string. * */ - @JRubyMethod(name = "unescape", required = 1, optional = 1, module = true) + @JRubyMethod(name = "unescape", required = 1, optional = 1, module = true, frame = true) public static IRubyObject cgiesc_unescape(ThreadContext context, IRubyObject self, IRubyObject[] argv) { IRubyObject _str = argv[0]; @@ -416,7 +416,7 @@ public static IRubyObject cgiesc_unescape(ThreadContext context, IRubyObject sel IRubyObject enc = accept_charset(argv, argv.length - 1, 1, self); return optimized_unescape(context.runtime, str, enc); } else { - return Helpers.invokeSuper(context, self, self.getMetaClass(), "unescape", argv, Block.NULL_BLOCK); + return Helpers.invokeSuper(context, self, argv, Block.NULL_BLOCK); } } @@ -424,9 +424,9 @@ public void load(Ruby runtime, boolean wrap) { RubyClass rb_cCGI = runtime.defineClass("CGI", runtime.getObject(), runtime.getObject().getAllocator()); RubyModule rb_mEscape = rb_cCGI.defineModuleUnder("Escape"); rb_mEscape.defineAnnotatedMethods(CGIEscape.class); - RubyModule rb_mUtil = rb_cCGI.defineModuleUnder("Util"); - rb_mUtil.prependModule(rb_mEscape); - rb_mEscape.extend_object(rb_cCGI); + // We do this in cgi/util.rb to work around jruby/jruby#4531. +// rb_mUtil.prependModule(rb_mEscape); +// rb_mEscape.extend_object(rb_cCGI); } // PORTED FROM OTHER FILES IN MRI diff --git a/lib/ruby/stdlib/cgi/util.rb b/lib/ruby/stdlib/cgi/util.rb index 66fa54d8e90..5fb247d48ab 100644 --- a/lib/ruby/stdlib/cgi/util.rb +++ b/lib/ruby/stdlib/cgi/util.rb @@ -1,5 +1,19 @@ # frozen_string_literal: false -class CGI; module Util; end; extend Util; end + +# We do this here to work around jruby/jruby#4531 +begin + require 'cgi/escape' +rescue LoadError +end +class CGI + module Util + prepend Escape + end + + extend Util + extend Escape +end + module CGI::Util @@accept_charset="UTF-8" unless defined?(@@accept_charset) # URL-encode a string. @@ -50,7 +64,8 @@ def escapeHTML(string) string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__) end - begin + # We do this above to work around jruby/jruby#4531 + false && begin require 'cgi/escape' rescue LoadError end