Skip to content

Commit

Permalink
Partially fix super handling in CGI, CGI::Util, CGI::Escape.
Browse files Browse the repository at this point in the history
See #4531.
See #4293.
  • Loading branch information
headius committed Mar 15, 2017
1 parent 7911cb1 commit 72d88ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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];

Expand All @@ -416,17 +416,17 @@ 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);
}
}

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
Expand Down
19 changes: 17 additions & 2 deletions 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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72d88ba

Please sign in to comment.