ICU-8569 Terminate the UTF-7 byte buffer with MINUS when flushing

X-SVN-Rev: 30175
This commit is contained in:
Michael Ow 2011-06-01 16:25:22 +00:00
parent 5ef5a3bed2
commit 96a2328093
3 changed files with 40 additions and 14 deletions

View File

@ -1,6 +1,6 @@
/* /*
********************************************************************** **********************************************************************
* Copyright (C) 2002-2010, International Business Machines * Copyright (C) 2002-2011, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
********************************************************************** **********************************************************************
* file name: ucnv_u7.c * file name: ucnv_u7.c
@ -688,14 +688,26 @@ unicodeMode:
if(pArgs->flush && source>=sourceLimit) { if(pArgs->flush && source>=sourceLimit) {
/* flush remaining bits to the target */ /* flush remaining bits to the target */
if(!inDirectMode && base64Counter!=0) { if(!inDirectMode) {
if (base64Counter!=0) {
if(target<targetLimit) {
*target++=toBase64[bits];
if(offsets!=NULL) {
*offsets++=sourceIndex-1;
}
} else {
cnv->charErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits];
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
}
/* Add final MINUS to terminate unicodeMode */
if(target<targetLimit) { if(target<targetLimit) {
*target++=toBase64[bits]; *target++=MINUS;
if(offsets!=NULL) { if(offsets!=NULL) {
*offsets++=sourceIndex-1; *offsets++=sourceIndex-1;
} }
} else { } else {
cnv->charErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits]; cnv->charErrorBuffer[cnv->charErrorBufferLength++]=MINUS;
*pErrorCode=U_BUFFER_OVERFLOW_ERROR; *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
} }
} }

View File

@ -469,9 +469,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen,
if(expectLen != targ-junkout) { if(expectLen != targ-junkout) {
log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
printf("\nGot:"); fprintf(stderr, "Got:\n");
printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout)); printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
printf("\nExpected:"); fprintf(stderr, "Expected:\n");
printSeqErr((const unsigned char*)expect, expectLen); printSeqErr((const unsigned char*)expect, expectLen);
return TC_MISMATCH; return TC_MISMATCH;
} }
@ -502,9 +502,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen,
} else { } else {
log_err("String does not match u->%s\n", gNuConvTestName); log_err("String does not match u->%s\n", gNuConvTestName);
printUSeqErr(source, sourceLen); printUSeqErr(source, sourceLen);
printf("\nGot:"); fprintf(stderr, "Got:\n");
printSeqErr((const unsigned char *)junkout, expectLen); printSeqErr((const unsigned char *)junkout, expectLen);
printf("\nExpected:"); fprintf(stderr, "Expected:\n");
printSeqErr((const unsigned char *)expect, expectLen); printSeqErr((const unsigned char *)expect, expectLen);
return TC_MISMATCH; return TC_MISMATCH;
@ -955,12 +955,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
Hi Mom -+Jjo--! Hi Mom -+Jjo--!
A+ImIDkQ. A+ImIDkQ.
+- +-
+ZeVnLIqe +ZeVnLIqe-
*/ */
0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21, 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21,
0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
0x2b, 0x2d, 0x2b, 0x2d,
0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
}; };
static const UChar unicode[] = { static const UChar unicode[] = {
/* /*
@ -984,7 +984,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10,
11, 12, 12, 12, 13, 13, 13, 13, 14, 11, 12, 12, 12, 13, 13, 13, 13, 14,
15, 15, 15, 15,
16, 16, 16, 17, 17, 17, 18, 18, 18 16, 16, 16, 17, 17, 17, 18, 18, 18, 18
}; };
/* same but escaping set O (the exclamation mark) */ /* same but escaping set O (the exclamation mark) */
@ -993,12 +993,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
Hi Mom -+Jjo--+ACE- Hi Mom -+Jjo--+ACE-
A+ImIDkQ. A+ImIDkQ.
+- +-
+ZeVnLIqe +ZeVnLIqe-
*/ */
0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d, 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d,
0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
0x2b, 0x2d, 0x2b, 0x2d,
0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
}; };
static const int32_t toUnicodeOffsetsR[] = { static const int32_t toUnicodeOffsetsR[] = {
0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15, 0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15,
@ -1010,7 +1010,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10,
11, 12, 12, 12, 13, 13, 13, 13, 14, 11, 12, 12, 12, 13, 13, 13, 13, 14,
15, 15, 15, 15,
16, 16, 16, 17, 17, 17, 18, 18, 18 16, 16, 16, 17, 17, 17, 18, 18, 18, 18
}; };
testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE); testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE);

View File

@ -973,6 +973,13 @@ conversion:table(nofallback) {
:intvector{}, :intvector{},
:int{0}, :int{0}, "illegal", ".", :bin{ 0e } :int{0}, :int{0}, "illegal", ".", :bin{ 0e }
} }
{
"UTF-7",
:bin{ 2b414b4d2d492b414b4d4170412d },
"\u00a3I\u00a3\u00a4",
:intvector{ 1,5,7,9 },
:int{0}, :int{0}, "", ".", :bin{""}
}
} }
} }
@ -1778,6 +1785,13 @@ conversion:table(nofallback) {
:intvector{ 0,0,0,0,2,2,3,3,4,4 }, :intvector{ 0,0,0,0,2,2,3,3,4,4 },
:int{1}, :int{0}, "", "0", "" :int{1}, :int{0}, "", "0", ""
} }
{
"UTF-7",
"\u00a3I\u00a3\u00a4",
:bin{ 2b414b4d2d492b414b4d4170412d },
:intvector{ 0,0,0,0,0,1,2,2,2,3,3,3,3,3 },
:int{1}, :int{0}, "", "0", ""
}
} }
} }