Skip to content

Commit

Permalink
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1599,7 +1599,7 @@ private IRubyObject multiByteCasecmp(Ruby runtime, Encoding enc, ByteList value,
}

int cl, ocl;
if (Encoding.isAscii(c) && Encoding.isAscii(oc)) {
if (enc.isAsciiCompatible() && Encoding.isAscii(c) && Encoding.isAscii(oc)) {
byte uc = AsciiTables.ToUpperCaseTable[c];
byte uoc = AsciiTables.ToUpperCaseTable[oc];
if (uc != uoc) {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -381,7 +381,7 @@ public static long getAscii(Encoding enc, byte[]bytes, int p, int end, int len)

public static int preciseCodePoint(Encoding enc, byte[]bytes, int p, int end) {
int l = preciseLength(enc, bytes, p, end);
if (l > 0) enc.mbcToCode(bytes, p, end);
if (l > 0) return enc.mbcToCode(bytes, p, end);
return -1;
}

19 changes: 19 additions & 0 deletions spec/regression/GH-1675_casecmp_on_UTF16LE_encoded_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://github.com/jruby/jruby/issues/1675
if RUBY_VERSION > '1.9'
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
end
end
end
end

0 comments on commit 2442c94

Please sign in to comment.