Fix AsciiString.contentEqualsIgnoreCase

Motivation:

Related to issue #4564.

AsciiString.contentEqualsIgnoreCase fails when comparing two AsciiStrings of the same length

Modifications:

Compare the values of the first AsciiString to the second AsciiString

Result:

AsciiString.contentEqualsIgnoreCase works as expected
This commit is contained in:
Brendt Lucas 2015-12-12 17:40:26 +00:00 committed by Norman Maurer
parent e5386b05e6
commit e8eda1b99f
2 changed files with 11 additions and 1 deletions

View File

@ -530,7 +530,7 @@ public final class AsciiString implements CharSequence, Comparable<CharSequence>
if (string.getClass() == AsciiString.class) { if (string.getClass() == AsciiString.class) {
AsciiString rhs = (AsciiString) string; AsciiString rhs = (AsciiString) string;
for (int i = arrayOffset(), j = rhs.arrayOffset(); i < length(); ++i, ++j) { for (int i = arrayOffset(), j = rhs.arrayOffset(); i < length(); ++i, ++j) {
if (!equalsIgnoreCase(value[i], value[j])) { if (!equalsIgnoreCase(value[i], rhs.value[j])) {
return false; return false;
} }
} }

View File

@ -240,6 +240,16 @@ public class AsciiStringCharacterTest {
assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false)); assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false)); assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true)); assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
// Test variations (Ascii + String, Ascii + Ascii, String + Ascii)
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), "fOo"), is(true));
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), new AsciiString("fOo")), is(true));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", new AsciiString("fOo")), is(true));
// Test variations (Ascii + String, Ascii + Ascii, String + Ascii)
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), "bAr"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), new AsciiString("bAr")), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", new AsciiString("bAr")), is(false));
} }
@Test @Test