Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1274b3553116
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 72d88bac5bbc
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 15, 2017

  1. Copy the full SHA
    7911cb1 View commit details
  2. Copy the full SHA
    72d88ba View commit details
Showing with 41 additions and 13 deletions.
  1. +13 −0 core/src/main/java/org/jruby/RubyConverter.java
  2. +11 −11 core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java
  3. +17 −2 lib/ruby/stdlib/cgi/util.rb
13 changes: 13 additions & 0 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.Ptr;
import org.jcodings.specific.ISO8859_1Encoding;
import org.jcodings.specific.UTF16BEEncoding;
import org.jcodings.specific.UTF16LEEncoding;
import org.jcodings.specific.UTF32BEEncoding;
@@ -95,9 +96,21 @@ public class RubyConverter extends RubyObject {
NONASCII_TO_ASCII.put(UTF16LEEncoding.INSTANCE, UTF8Encoding.INSTANCE);
NONASCII_TO_ASCII.put(UTF32BEEncoding.INSTANCE, UTF8Encoding.INSTANCE);
NONASCII_TO_ASCII.put(UTF32LEEncoding.INSTANCE, UTF8Encoding.INSTANCE);
NONASCII_TO_ASCII.put(
EncodingDB.getEncodings().get("CP50220".getBytes()).getEncoding(),
EncodingDB.getEncodings().get("CP51932".getBytes()).getEncoding());
NONASCII_TO_ASCII.put(
EncodingDB.getEncodings().get("CP50221".getBytes()).getEncoding(),
EncodingDB.getEncodings().get("CP51932".getBytes()).getEncoding());
NONASCII_TO_ASCII.put(EncodingDB.getEncodings().get("IBM037".getBytes()).getEncoding(), ISO8859_1Encoding.INSTANCE);
NONASCII_TO_ASCII.put(EncodingDB.getEncodings().get("UTF-16".getBytes()).getEncoding(), UTF8Encoding.INSTANCE);
NONASCII_TO_ASCII.put(EncodingDB.getEncodings().get("UTF-32".getBytes()).getEncoding(), UTF8Encoding.INSTANCE);
NONASCII_TO_ASCII.put(
EncodingDB.getEncodings().get("ISO-2022-JP".getBytes()).getEncoding(),
EncodingDB.getEncodings().get("stateless-ISO-2022-JP".getBytes()).getEncoding());
NONASCII_TO_ASCII.put(
EncodingDB.getEncodings().get("ISO-2022-JP-KDDI".getBytes()).getEncoding(),
EncodingDB.getEncodings().get("stateless-ISO-2022-JP-KDDI".getBytes()).getEncoding());
}

public static RubyClass createConverterClass(Ruby runtime) {
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/ext/cgi/escape/CGIEscape.java
Original file line number Diff line number Diff line change
@@ -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,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
19 changes: 17 additions & 2 deletions lib/ruby/stdlib/cgi/util.rb
Original file line number Diff line number Diff line change
@@ -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