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: 1c98caacba80
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c07398de11ad
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Feb 20, 2016

  1. Fix this BOM UTF check to be case-insensitive.

    Fixes MRI TestIO_M17N#test_strip_bom.
    headius committed Feb 20, 2016
    Copy the full SHA
    168d854 View commit details
  2. Copy the full SHA
    e003b23 View commit details
  3. Fixes to Array and base inspect logic.

    Fixes MRI TestM17N#test_inspect_with_default_internal.
    headius committed Feb 20, 2016
    Copy the full SHA
    c07398d View commit details
16 changes: 9 additions & 7 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@
import org.jruby.util.Qsort;
import org.jruby.util.RecursiveComparator;
import org.jruby.util.TypeConverter;
import org.jruby.util.io.EncodingUtils;

import java.io.IOException;
import java.lang.reflect.Array;
@@ -1433,28 +1434,29 @@ public RubyArray concat19(IRubyObject obj) {
*/
private IRubyObject inspectAry(ThreadContext context) {
final Ruby runtime = context.runtime;
Encoding encoding = runtime.getDefaultInternalEncoding();
if (encoding == null) encoding = USASCIIEncoding.INSTANCE;
RubyString str = RubyString.newStringLight(runtime, DEFAULT_INSPECT_STR_SIZE, encoding);
str.cat((byte)'[');
RubyString str = RubyString.newStringLight(runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE);
EncodingUtils.strBufCat(runtime, str, OPEN_BRACKET);
boolean tainted = isTaint();

for (int i = 0; i < realLength; i++) {

RubyString s = inspect(context, safeArrayRef(runtime, values, begin + i));
if (s.isTaint()) tainted = true;
if (i > 0) str.cat(',', encoding).cat(' ', encoding);
if (i > 0) EncodingUtils.strBufCat(runtime, str, COMMA_SPACE);
else str.setEncoding(s.getEncoding());

str.cat19(s);
}
str.cat(']', encoding);
EncodingUtils.strBufCat(runtime, str, CLOSE_BRACKET);

if (tainted) str.setTaint(true);

return str;
}

private static final ByteList OPEN_BRACKET = new ByteList(new byte[]{(byte)'['}, USASCIIEncoding.INSTANCE);
private static final ByteList CLOSE_BRACKET = new ByteList(new byte[]{(byte)']'}, USASCIIEncoding.INSTANCE);
private static final ByteList COMMA_SPACE = new ByteList(new byte[]{(byte)',', (byte)' '}, USASCIIEncoding.INSTANCE);

/** rb_ary_inspect
*
*/
15 changes: 9 additions & 6 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1096,14 +1096,17 @@ public IRubyObject hashyInspect() {
public static IRubyObject rbInspect(ThreadContext context, IRubyObject obj) {
Ruby runtime = context.runtime;
RubyString str = obj.callMethod(context, "inspect").asString();
Encoding ext = EncodingUtils.defaultExternalEncoding(runtime);
if (!ext.isAsciiCompatible()) {
if (!str.isAsciiOnly())
throw runtime.newEncodingCompatibilityError("inspected result must be ASCII only if default external encoding is ASCII incompatible");
Encoding enc = runtime.getDefaultInternalEncoding();
if (enc == null) enc = runtime.getDefaultExternalEncoding();
if (!enc.isAsciiCompatible()) {
if (!str.isAsciiOnly()) {
return RubyString.inspect19(runtime, str.getByteList());
}
return str;
}
if (str.getEncoding() != ext && !str.isAsciiOnly())
throw runtime.newEncodingCompatibilityError("inspected result must be ASCII only or use the default external encoding");
if (str.getEncoding() != enc && !str.isAsciiOnly()) {
return RubyString.inspect19(runtime, str.getByteList());
}
return str;
}
/**
14 changes: 1 addition & 13 deletions core/src/main/java/org/jruby/RubyObject.java
Original file line number Diff line number Diff line change
@@ -513,19 +513,7 @@ public int hashCode() {
* Prefered over callMethod(context, "inspect")
*/
public static RubyString inspect(ThreadContext context, IRubyObject object) {
Ruby runtime = context.runtime;
RubyString str = RubyString.objAsString(context, object.callMethod(context, "inspect"));
Encoding ext = runtime.getDefaultExternalEncoding();
if (!ext.isAsciiCompatible()) {
if (!str.isAsciiOnly()) {
return EncodingUtils.rbStrEscape(runtime, str);
}
return str;
}
if (str.getEncoding() != ext && !str.isAsciiOnly()) {
return EncodingUtils.rbStrEscape(runtime, str);
}
return str;
return (RubyString)rbInspect(context, object);
}

// MRI: rb_obj_dig
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1970,6 +1970,7 @@ public IRubyObject inspect19() {
return inspect19(getRuntime(), value).infectBy(this);
}

// MRI: rb_str_escape
public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
Encoding enc = byteList.getEncoding();
byte bytes[] = byteList.getUnsafeBytes();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ public static void parseModeEncoding(ThreadContext context, IOEncodable ioEncoda

if (estr.toLowerCase().startsWith("bom|")) {
estr = estr.substring(4);
if (estr.startsWith("utf-")) {
if (estr.toLowerCase().startsWith("utf-")) {
fmode_p[0] |= OpenFile.SETENC_BY_BOM;
ioEncodable.setBOM(true);
} else {
1 change: 1 addition & 0 deletions test/mri/excludes/TestIO_M17N.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exclude :test_both_textmode_binmode, "needs investigation"
exclude :test_cbuf, "needs investigation"
exclude :test_each_codepoint_need_more, "times out, but doesn't pass even with longer timeout"
exclude :test_error_nonascii, "needs investigation"
exclude :test_getc_newlineconv_invalid, "needs investigation"
exclude :test_inspect_nonascii, "needs investigation"