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

Commits on Mar 13, 2015

  1. Copy the full SHA
    912e77d View commit details
  2. Tweak this spec to run all encodings and skip dummies.

    This makes the test run and pass the same as in MRI.
    headius committed Mar 13, 2015
    Copy the full SHA
    1dbeb43 View commit details
Showing with 11 additions and 13 deletions.
  1. +6 −3 core/src/main/java/org/jruby/RubyString.java
  2. +5 −10 spec/regression/GH-1675_casecmp_on_UTF16LE_encoded_string_spec.rb
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -2088,6 +2088,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
result.associateEncoding(resultEnc);

boolean isUnicode = StringSupport.isUnicode(enc);
boolean asciiCompat = enc.isAsciiCompatible();

EncodingDB.Entry e = null;
CaseInsensitiveBytesHash<EncodingDB.Entry> encodings = runtime.getEncodingService().getEncodings();
@@ -2100,6 +2101,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
} else if (c0 == 0xFF && c1 == 0xFE) {
e = encodings.get("UTF-16LE".getBytes());
} else {
e = encodings.get("ASCII-8BIT".getBytes());
isUnicode = false;
}
} else if (enc == encodings.get("UTF-32".getBytes()).getEncoding() && end - p > 3) {
@@ -2113,6 +2115,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
} else if (c3 == 0 && c2 == 0 && c1 == 0xFE && c0 == 0xFF) {
e = encodings.get("UTF-32LE".getBytes());
} else {
e = encodings.get("ASCII-8BIT".getBytes());
isUnicode = false;
}
}
@@ -2137,13 +2140,13 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
}
int c = enc.mbcToCode(bytes, p, end);
p += n;
if ((enc.isAsciiCompatible() || isUnicode) &&
if ((asciiCompat || isUnicode) &&
(c == '"' || c == '\\' ||
(c == '#' && p < end && (StringSupport.preciseLength(enc, bytes, p, end) > 0) &&
(cc = codePoint(runtime, enc, bytes, p, end)) == '$' || cc == '@' || cc == '{'))) {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
result.cat('\\');
if (enc.isAsciiCompatible() || enc == resultEnc) {
if (asciiCompat || enc == resultEnc) {
prev = p - n;
continue;
}
@@ -2169,7 +2172,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
continue;
}

if ((enc == resultEnc && enc.isPrint(c)) || (enc.isAsciiCompatible() && Encoding.isAscii(c) && enc.isPrint(c))) {
if ((enc == resultEnc && enc.isPrint(c)) || (asciiCompat && Encoding.isAscii(c) && enc.isPrint(c))) {
continue;
} else {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
15 changes: 5 additions & 10 deletions spec/regression/GH-1675_casecmp_on_UTF16LE_encoded_string_spec.rb
Original file line number Diff line number Diff line change
@@ -3,16 +3,11 @@
describe 'String#casecmp' do
it 'returns correct value' do
Encoding.name_list.each do |enc_name|
if (enc_name != "UTF-7") && (enc_name != "CP65000")
# this condition statement escape the following error:
# Encoding::ConverterNotFoundError:
# code converter not found for UTF-7

# using "UTF-16LE", "UTF-8", "Shift_JIS", and other available encodings
a = 'ABC'.encode(enc_name)
b = 'ABC'.encode(enc_name)
b.casecmp(a).should be_true
end
enc = Encoding.find(enc_name)
next if !enc || enc.dummy?
a = 'ABC'.encode(enc)
b = 'ABC'.encode(enc)
b.casecmp(a).should == 0
end
end
end