ICU-5273 fix IDNAToUnicode to not fail on error
X-SVN-Rev: 21278
This commit is contained in:
parent
0bbbe4b84f
commit
c135088734
@ -614,8 +614,24 @@ CLEANUP:
|
||||
}
|
||||
uprv_free(caseFlags);
|
||||
|
||||
// delete prep;
|
||||
|
||||
// The RFC states that
|
||||
// <quote>
|
||||
// ToUnicode never fails. If any step fails, then the original input
|
||||
// is returned immediately in that step.
|
||||
// </quote>
|
||||
// So if any step fails lets copy source to destination
|
||||
if(U_FAILURE(*status)){
|
||||
//copy the source to destination
|
||||
if(dest && srcLength <= destCapacity){
|
||||
if(srcLength == -1) {
|
||||
uprv_memmove(dest,src,u_strlen(src)* U_SIZEOF_UCHAR);
|
||||
} else {
|
||||
uprv_memmove(dest,src,srcLength * U_SIZEOF_UCHAR);
|
||||
}
|
||||
}
|
||||
reqLength = srcLength;
|
||||
*status = U_ZERO_ERROR;
|
||||
}
|
||||
return u_terminateUChars(dest, destCapacity, reqLength, status);
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.XN--8mb5595fsoa28orucya378bqre2tcwop06c5qbw82a1rffmae0361dea96b.com",
|
||||
U_IDNA_PROHIBITED_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
|
||||
{
|
||||
@ -268,7 +268,7 @@ static const struct ErrorCases{
|
||||
"www.XN--6lA2Bz548Fj1GuA391Bf1Gb1N59Ab29A7iA.com",
|
||||
|
||||
U_IDNA_UNASSIGNED_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -281,7 +281,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.xn--ghBGI4851OiyA33VqrD6Az86C4qF83CtRv93D5xBk15AzfG0nAgA0578DeA71C.com",
|
||||
U_IDNA_CHECK_BIDI_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -296,7 +296,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.xn----b95Ew8SqA315Ao5FbuMlnNmhA.com",
|
||||
U_IDNA_STD3_ASCII_RULES_ERROR,
|
||||
TRUE, TRUE, FALSE
|
||||
TRUE, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -328,7 +328,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.xn--989AoMsVi5E83Db1D2A355Cv1E0vAk1DwRv93D5xBh15A0Dt30A5JpSD879Ccm6FeA98C.com",
|
||||
U_IDNA_LABEL_TOO_LONG_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
|
||||
{
|
||||
@ -340,7 +340,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.xn--01-tvdmo.com",
|
||||
U_IDNA_CHECK_BIDI_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
|
||||
{
|
||||
@ -352,7 +352,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.XN--ghbgi278xia.com",
|
||||
U_IDNA_PROHIBITED_ERROR,
|
||||
FALSE, TRUE, TRUE
|
||||
FALSE, FALSE, TRUE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -363,7 +363,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.-abcde.com",
|
||||
U_IDNA_STD3_ASCII_RULES_ERROR,
|
||||
TRUE, TRUE, FALSE
|
||||
TRUE, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -374,7 +374,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.abcde-.com",
|
||||
U_IDNA_STD3_ASCII_RULES_ERROR,
|
||||
TRUE, TRUE, FALSE
|
||||
TRUE, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -385,7 +385,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www.abcde@.com",
|
||||
U_IDNA_STD3_ASCII_RULES_ERROR,
|
||||
TRUE, TRUE, FALSE
|
||||
TRUE, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
{
|
||||
@ -396,7 +396,7 @@ static const struct ErrorCases{
|
||||
},
|
||||
"www..com",
|
||||
U_IDNA_ZERO_LENGTH_LABEL_ERROR,
|
||||
TRUE, TRUE, FALSE
|
||||
TRUE, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
{0},
|
||||
@ -407,193 +407,6 @@ static const struct ErrorCases{
|
||||
};
|
||||
|
||||
|
||||
static const struct ConformanceTestCases
|
||||
{
|
||||
const char *comment;
|
||||
const char *in;
|
||||
const char *out;
|
||||
const char *profile;
|
||||
int32_t flags;
|
||||
UErrorCode expectedStatus;
|
||||
}
|
||||
conformanceTestCases[] =
|
||||
{
|
||||
|
||||
{
|
||||
"Case folding ASCII U+0043 U+0041 U+0046 U+0045",
|
||||
"\x43\x41\x46\x45", "\x63\x61\x66\x65",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_ZERO_ERROR
|
||||
|
||||
},
|
||||
{
|
||||
"Case folding 8bit U+00DF (german sharp s)",
|
||||
"\xC3\x9F", "\x73\x73",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_ZERO_ERROR
|
||||
},
|
||||
{
|
||||
"Non-ASCII multibyte space character U+1680",
|
||||
"\xE1\x9A\x80", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Non-ASCII 8bit control character U+0085",
|
||||
"\xC2\x85", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Non-ASCII multibyte control character U+180E",
|
||||
"\xE1\xA0\x8E", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Non-ASCII control character U+1D175",
|
||||
"\xF0\x9D\x85\xB5", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Plane 0 private use character U+F123",
|
||||
"\xEF\x84\xA3", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Plane 15 private use character U+F1234",
|
||||
"\xF3\xB1\x88\xB4", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Plane 16 private use character U+10F234",
|
||||
"\xF4\x8F\x88\xB4", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Non-character code point U+8FFFE",
|
||||
"\xF2\x8F\xBF\xBE", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Non-character code point U+10FFFF",
|
||||
"\xF4\x8F\xBF\xBF", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
/*
|
||||
{
|
||||
"Surrogate code U+DF42",
|
||||
"\xED\xBD\x82", NULL, "Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
*/
|
||||
{
|
||||
"Non-plain text character U+FFFD",
|
||||
"\xEF\xBF\xBD", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Ideographic description character U+2FF5",
|
||||
"\xE2\xBF\xB5", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Display property character U+0341",
|
||||
"\xCD\x81", "\xCC\x81",
|
||||
"Nameprep", UIDNA_DEFAULT, U_ZERO_ERROR
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
"Left-to-right mark U+200E",
|
||||
"\xE2\x80\x8E", "\xCC\x81",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
|
||||
"Deprecated U+202A",
|
||||
"\xE2\x80\xAA", "\xCC\x81",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Language tagging character U+E0001",
|
||||
"\xF3\xA0\x80\x81", "\xCC\x81",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Language tagging character U+E0042",
|
||||
"\xF3\xA0\x81\x82", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_PROHIBITED_ERROR
|
||||
},
|
||||
{
|
||||
"Bidi: RandALCat character U+05BE and LCat characters",
|
||||
"\x66\x6F\x6F\xD6\xBE\x62\x61\x72", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_CHECK_BIDI_ERROR
|
||||
},
|
||||
{
|
||||
"Bidi: RandALCat character U+FD50 and LCat characters",
|
||||
"\x66\x6F\x6F\xEF\xB5\x90\x62\x61\x72", NULL,
|
||||
"Nameprep",UIDNA_DEFAULT ,
|
||||
U_IDNA_CHECK_BIDI_ERROR
|
||||
},
|
||||
{
|
||||
"Bidi: RandALCat character U+FB38 and LCat characters",
|
||||
"\x66\x6F\x6F\xEF\xB9\xB6\x62\x61\x72", "\x66\x6F\x6F\x20\xd9\x8e\x62\x61\x72",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_ZERO_ERROR
|
||||
},
|
||||
{ "Bidi: RandALCat without trailing RandALCat U+0627 U+0031",
|
||||
"\xD8\xA7\x31", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_CHECK_BIDI_ERROR
|
||||
},
|
||||
{
|
||||
"Bidi: RandALCat character U+0627 U+0031 U+0628",
|
||||
"\xD8\xA7\x31\xD8\xA8", "\xD8\xA7\x31\xD8\xA8",
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_ZERO_ERROR
|
||||
},
|
||||
{
|
||||
"Unassigned code point U+E0002",
|
||||
"\xF3\xA0\x80\x82", NULL,
|
||||
"Nameprep", UIDNA_DEFAULT,
|
||||
U_IDNA_UNASSIGNED_ERROR
|
||||
},
|
||||
|
||||
/* // Invalid UTF-8
|
||||
{
|
||||
"Larger test (shrinking)",
|
||||
"X\xC2\xAD\xC3\xDF\xC4\xB0\xE2\x84\xA1\x6a\xcc\x8c\xc2\xa0\xc2"
|
||||
"\xaa\xce\xb0\xe2\x80\x80", "xssi\xcc\x87""tel\xc7\xb0 a\xce\xb0 ",
|
||||
"Nameprep",
|
||||
UIDNA_DEFAULT, U_ZERO_ERROR
|
||||
},
|
||||
{
|
||||
|
||||
"Larger test (expanding)",
|
||||
"X\xC3\xDF\xe3\x8c\x96\xC4\xB0\xE2\x84\xA1\xE2\x92\x9F\xE3\x8c\x80",
|
||||
"xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88"
|
||||
"\xe3\x83\xab""i\xcc\x87""tel\x28""d\x29\xe3\x82\xa2\xe3\x83\x91"
|
||||
"\xe3\x83\xbc\xe3\x83\x88"
|
||||
"Nameprep",
|
||||
UIDNA_DEFAULT, U_ZERO_ERROR
|
||||
},
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define MAX_DEST_SIZE 300
|
||||
@ -1119,7 +932,7 @@ void TestIDNA::testErrorCases(const char* IDNToASCIIName, TestFunc IDNToASCII,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void TestIDNA::testConformance(const char* toASCIIName, TestFunc toASCII,
|
||||
const char* IDNToASCIIName, TestFunc IDNToASCII,
|
||||
const char* IDNToUnicodeName, TestFunc IDNToUnicode,
|
||||
@ -1174,7 +987,7 @@ void TestIDNA::testConformance(const char* toASCIIName, TestFunc toASCII,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
// test and ascertain
|
||||
// func(func(func(src))) == func(src)
|
||||
void TestIDNA::testChaining(const UChar* src,int32_t numIterations,const char* testName,
|
||||
@ -1440,8 +1253,7 @@ void TestIDNA::runIndexedTest( int32_t index, UBool exec, const char* &name, cha
|
||||
case 9: name = "TestDataFile"; if(exec) TestDataFile(); break;
|
||||
case 10: name = "TestRefIDNA"; if(exec) TestRefIDNA(); break;
|
||||
case 11: name = "TestIDNAMonkeyTest"; if(exec) TestIDNAMonkeyTest(); break;
|
||||
case 12: name = "TestConformance"; if(exec) TestConformance();break;
|
||||
case 13:
|
||||
case 12:
|
||||
{
|
||||
name = "TestConformanceTestVectors";
|
||||
if(exec){
|
||||
@ -1482,10 +1294,7 @@ void TestIDNA::TestRootLabelSeparator(){
|
||||
void TestIDNA::TestChaining(){
|
||||
testChaining("uidna_toASCII",uidna_toASCII, "uidna_toUnicode", uidna_toUnicode);
|
||||
}
|
||||
void TestIDNA::TestConformance(){
|
||||
testConformance("uidna_toASCII",uidna_toASCII,"uidna_IDNToASCII",uidna_IDNToASCII,
|
||||
"uidna_IDNToUnicode",uidna_IDNToUnicode, "uidna_toUnicode", uidna_toUnicode);
|
||||
}
|
||||
|
||||
|
||||
static const int loopCount = 100;
|
||||
static const int maxCharCount = 20;
|
||||
|
Loading…
Reference in New Issue
Block a user