ICU-8484 fix the problem with infinite loop with surrogates for collation

X-SVN-Rev: 30184
This commit is contained in:
Dragan Besevic 2011-06-02 19:56:42 +00:00
parent 7078702c9f
commit b22717a642
2 changed files with 22 additions and 4 deletions

View File

@ -1690,10 +1690,19 @@ public final class CollationElementIterator
// Source string char was not in contraction table.
// Unless it is a discontiguous contraction, we are done
int miss = ch;
if(UTF16.isLeadSurrogate(ch)) { // in order to do the proper detection, we
// need to see if we're dealing with a supplementary
miss = UCharacterProperty.getRawSupplementary(ch, (char) nextChar());
}
// ticket 8484 - porting changes from C for 6101
// We test whether the next two char are surrogate pairs.
// This test is done if the iterator is not in the end.
// If there is no surrogate pair, the iterator
// goes back one if needed.
if(UTF16.isLeadSurrogate(ch) && !isEnd()) {
char surrNextChar = (char)nextChar();
if (UTF16.isTrailSurrogate(surrNextChar)) {
miss = UCharacterProperty.getRawSupplementary(ch, surrNextChar);
} else {
previousChar();
}
}
int sCC;
if (maxCC == 0 || (sCC = getCombiningClass(miss)) == 0
|| sCC > maxCC || (allSame != 0 && sCC == maxCC) ||

View File

@ -1135,6 +1135,15 @@ public class CollationRegressionTest extends TestFmwk {
}
}
// Fixing the infinite loop for surrogates
public void Test8484()
{
String s = "\u9FE1\uCEF3\u2798\uAAB6\uDA7C";
Collator coll = Collator.getInstance();
CollationKey collKey = coll.getCollationKey(s);
logln("Pass: " + collKey.toString() + " generated OK.");
}
public void TestBengaliSortKey() throws Exception {
char rules[] = { 0x26, 0x9fa, 0x3c, 0x98c, 0x3c, 0x9e1, 0x3c, 0x98f, 0x3c, 0x990, 0x3c, 0x993,
0x3c, 0x994, 0x3c, 0x9bc, 0x3c, 0x982, 0x3c, 0x983, 0x3c, 0x981, 0x3c, 0x9b0, 0x3c,