ICU-5571 add IDNA fixes to maint-3-4 branch

X-SVN-Rev: 20989
This commit is contained in:
Ram Viswanadha 2007-01-27 01:05:52 +00:00
parent abcecc25f9
commit f8c168bc86
3 changed files with 70 additions and 5 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2003-2005, International Business Machines
* Copyright (C) 2003-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -235,7 +235,14 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
if(srcLength == -1){
srcLength = u_strlen(src);
}
if(srcLength > b1Capacity){
b1 = (UChar*) uprv_malloc(srcLength * U_SIZEOF_UCHAR);
if(b1==NULL){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
}
b1Capacity = srcLength;
}
// step 1
for( j=0;j<srcLength;j++){
if(src[j] > 0x7F){
@ -253,6 +260,9 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
if(*status == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
// we do not have enough room so grow the buffer
if(b1 != b1Stack){
uprv_free(b1);
}
b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR);
if(b1==NULL){
*status = U_MEMORY_ALLOCATION_ERROR;

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2003-2005, International Business Machines
* Copyright (C) 2003-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -36,6 +36,7 @@ static void TestCompare(void);
static void TestUnicode32Norm(void);
static void TestJB4490(void);
static void TestJB4475(void);
static void TestLength(void);
void addIDNATest(TestNode** root);
@ -63,6 +64,7 @@ addIDNATest(TestNode** root)
addTest(root, &TestUnicode32Norm,"idna/TestUnicode32Norm");
addTest(root, &TestJB4490, "idna/TestJB4490");
addTest(root, &TestJB4475, "idna/TestJB4475");
addTest(root, &TestLength, "idna/TestLength");
}
static void
@ -718,6 +720,47 @@ static void TestJB4475(){
}
}
}
static void TestLength(){
{
static const char* cl = "my_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";
UChar ul[128] = {'\0'};
UChar dest[256] = {'\0'};
int32_t destLen = LENGTHOF(dest);
UErrorCode status = U_ZERO_ERROR;
UParseError ps;
int32_t len = (int32_t)strlen(cl);
u_charsToUChars(cl, ul, len+1);
destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
if(status != U_ZERO_ERROR){
log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status));
}
status = U_ZERO_ERROR;
destLen = LENGTHOF(dest);
len = -1;
destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
if(status != U_ZERO_ERROR){
log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status));
}
status = U_ZERO_ERROR;
destLen = LENGTHOF(dest);
len = -1;
destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
log_err("uidna_toASCII failed with error %s.\n", u_errorName(status));
}
status = U_ZERO_ERROR;
destLen = LENGTHOF(dest);
len = -1;
destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
log_err("uidna_toASCII failed with error %s.\n", u_errorName(status));
}
}
}
#endif
/*

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2003-2005, International Business Machines
* Copyright (C) 2003-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -283,7 +283,16 @@ idnaref_toASCII(const UChar* src, int32_t srcLength,
if(srcLength == -1){
srcLength = u_strlen(src);
}
if(srcLength > b1Capacity){
b1 = (UChar*) uprv_malloc(srcLength * U_SIZEOF_UCHAR);
if(b1==NULL){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
}
b1Capacity = srcLength;
}
// step 1
for( j=0;j<srcLength;j++){
if(src[j] > 0x7F){
@ -303,6 +312,9 @@ idnaref_toASCII(const UChar* src, int32_t srcLength,
if(*status == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
/* we do not have enough room so grow the buffer*/
if(b1 != b1Stack){
uprv_free(b1);
}
b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR);
if(b1==NULL){
*status = U_MEMORY_ALLOCATION_ERROR;