From: Michael Ow Date: Wed, 1 Jun 2011 16:25:22 +0000 (+0000) Subject: ICU-8569 Terminate the UTF-7 byte buffer with MINUS when flushing X-Git-Tag: milestone-59-0-1~4752 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96a23280934e292034f70100c93fffed99cd2cb1;p=icu ICU-8569 Terminate the UTF-7 byte buffer with MINUS when flushing X-SVN-Rev: 30175 --- diff --git a/icu4c/source/common/ucnv_u7.c b/icu4c/source/common/ucnv_u7.c index 19b1105653d..84613283889 100644 --- a/icu4c/source/common/ucnv_u7.c +++ b/icu4c/source/common/ucnv_u7.c @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2002-2010, International Business Machines +* Copyright (C) 2002-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * file name: ucnv_u7.c @@ -688,14 +688,26 @@ unicodeMode: if(pArgs->flush && source>=sourceLimit) { /* flush remaining bits to the target */ - if(!inDirectMode && base64Counter!=0) { + if(!inDirectMode) { + if (base64Counter!=0) { + if(targetcharErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits]; + *pErrorCode=U_BUFFER_OVERFLOW_ERROR; + } + } + /* Add final MINUS to terminate unicodeMode */ if(targetcharErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits]; + cnv->charErrorBuffer[cnv->charErrorBufferLength++]=MINUS; *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } } diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c index 106ae7c24b7..24f241a43e8 100644 --- a/icu4c/source/test/cintltst/nucnvtst.c +++ b/icu4c/source/test/cintltst/nucnvtst.c @@ -469,9 +469,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, if(expectLen != targ-junkout) { 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); - printf("\nGot:"); + fprintf(stderr, "Got:\n"); printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout)); - printf("\nExpected:"); + fprintf(stderr, "Expected:\n"); printSeqErr((const unsigned char*)expect, expectLen); return TC_MISMATCH; } @@ -502,9 +502,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, } else { log_err("String does not match u->%s\n", gNuConvTestName); printUSeqErr(source, sourceLen); - printf("\nGot:"); + fprintf(stderr, "Got:\n"); printSeqErr((const unsigned char *)junkout, expectLen); - printf("\nExpected:"); + fprintf(stderr, "Expected:\n"); printSeqErr((const unsigned char *)expect, expectLen); return TC_MISMATCH; @@ -955,12 +955,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) Hi Mom -+Jjo--! A+ImIDkQ. +- - +ZeVnLIqe + +ZeVnLIqe- */ 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21, 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 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[] = { /* @@ -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, 11, 12, 12, 12, 13, 13, 13, 13, 14, 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) */ @@ -993,12 +993,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) Hi Mom -+Jjo--+ACE- A+ImIDkQ. +- - +ZeVnLIqe + +ZeVnLIqe- */ 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, 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[] = { 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, 11, 12, 12, 12, 13, 13, 13, 13, 14, 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); diff --git a/icu4c/source/test/testdata/conversion.txt b/icu4c/source/test/testdata/conversion.txt index 84f15fadb21..989a336e54a 100644 --- a/icu4c/source/test/testdata/conversion.txt +++ b/icu4c/source/test/testdata/conversion.txt @@ -973,6 +973,13 @@ conversion:table(nofallback) { :intvector{}, :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 }, :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", "" + } } }