From 2c7e5e4b29c80d5475e971232458d3481bbe7136 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Mon, 25 May 2020 21:41:18 +0800 Subject: [PATCH] [LANG-1545] CharSequenceUtils.regionMatches is wrong dealing with Georgian. (#529) * CharSequenceUtils.regionMatches is wrong dealing with Georgian. see details in tests. * refine tests --- .../commons/lang3/CharSequenceUtils.java | 7 ++--- .../apache/commons/lang3/StringUtilsTest.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java index 58c04536e..fdb91220b 100644 --- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java @@ -294,9 +294,10 @@ public class CharSequenceUtils { return false; } - // The same check as in String.regionMatches(): - if (Character.toUpperCase(c1) != Character.toUpperCase(c2) - && Character.toLowerCase(c1) != Character.toLowerCase(c2)) { + // The real same check as in String.regionMatches(): + char u1 = Character.toUpperCase(c1); + char u2 = Character.toUpperCase(c2); + if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) { return false; } } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 30263de6b..cea53a263 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -3305,4 +3305,31 @@ public class StringUtilsTest { Locale.setDefault(defaultLocales); } } + + @Test + public void testGeorgianSample() { + char[] arrayI = new char[]{ + //Latin Small Letter dotless I + (char) 0x0131, + //Greek Capital Letter Theta + (char) 0x03F4 + }; + char[] arrayJ = new char[]{ + //Latin Capital Letter I with dot above + (char) 0x0130, + //Greek Theta Symbol + (char) 0x03D1 + }; + for (char i : arrayI) { + for (char j : arrayJ) { + String si = "" + i; + String sj = "" + j; + boolean res1 = si.equalsIgnoreCase(sj); + CharSequence ci = new StringBuilder(si); + CharSequence cj = new StringBuilder(sj); + boolean res2 = StringUtils.startsWithIgnoreCase(ci, cj); + assertEquals(res1, res2, "si : " + si + " sj : " + sj); + } + } + } }