]> granicus.if.org Git - icu/commitdiff
ICU-8569 Terminate the UTF-7 byte buffer with MINUS when flushing
authorMichael Ow <mow@svn.icu-project.org>
Wed, 1 Jun 2011 16:25:22 +0000 (16:25 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Wed, 1 Jun 2011 16:25:22 +0000 (16:25 +0000)
X-SVN-Rev: 30175

icu4c/source/common/ucnv_u7.c
icu4c/source/test/cintltst/nucnvtst.c
icu4c/source/test/testdata/conversion.txt

index 19b1105653d8263113d60b5a86096c9fd0d5779b..84613283889be95f61ef8412685165b8a98503bf 100644 (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.
 **********************************************************************
 *   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(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) {
-                *target++=toBase64[bits];
+                *target++=MINUS;
                 if(offsets!=NULL) {
                     *offsets++=sourceIndex-1;
                 }
             } else {
-                cnv->charErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits];
+                cnv->charErrorBuffer[cnv->charErrorBufferLength++]=MINUS;
                 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
             }
         }
index 106ae7c24b71ab4a0719e293d3bc2d85bc9bfc10..24f241a43e828e895ddc53580fecfac905441166 100644 (file)
@@ -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);
index 84f15fadb2198cc4a63ee8b5f7b1925156defa50..989a336e54a1034703b51b0aa8939c86ba339c5e 100644 (file)
@@ -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", ""
+        }
       }
     }