Index: src/actions.cpp
===================================================================
--- src/actions.cpp	(revision 2002)
+++ src/actions.cpp	(working copy)
@@ -625,7 +625,7 @@
                 && (   md.typeId() == Exiv2::undefined
                     || md.typeId() == Exiv2::unsignedByte
                     || md.typeId() == Exiv2::signedByte)
-                && md.size() > 100) {
+                && md.size() > 128) {
                 std::cout << _("(Binary value suppressed)") << std::endl;
                 return;
             }
@@ -638,7 +638,7 @@
                 && (   md.typeId() == Exiv2::undefined
                     || md.typeId() == Exiv2::unsignedByte
                     || md.typeId() == Exiv2::signedByte)
-                && md.size() > 100) {
+                && md.size() > 128) {
                 std::cout << _("(Binary value suppressed)") << std::endl;
                 return;
             }
@@ -651,7 +651,7 @@
                 && (   md.typeId() == Exiv2::undefined
                     || md.typeId() == Exiv2::unsignedByte
                     || md.typeId() == Exiv2::signedByte)
-                && md.size() > 100) {
+                && md.size() > 128) {
                 std::cout << _("(Binary value suppressed)") << std::endl;
                 return;
             }
Index: src/convert.cpp
===================================================================
--- src/convert.cpp	(revision 2002)
+++ src/convert.cpp	(working copy)
@@ -508,6 +508,7 @@
             return;
         }
         // Todo: Convert to UTF-8 if necessary
+		
         (*xmpData_)[to] = cv->comment();
         if (erase_) exifData_->erase(pos);
     }
@@ -1325,7 +1326,7 @@
         std::string outstr;
         EXV_ICONV_CONST char *inptr = const_cast<char *>(str.c_str());
         size_t inbytesleft = str.length();
-        int outbytesProduced = 0;
+
         while (inbytesleft) {
             char outbuf[100];
             char *outptr = outbuf;
@@ -1335,7 +1336,8 @@
                               &inbytesleft,
                               &outptr,
                               &outbytesleft);
-            outbytesProduced += sizeof(outbuf) - 1 - outbytesleft;
+
+			int outbytesProduced = sizeof(outbuf) - 1 - outbytesleft;
             if (rc == size_t(-1) && errno != E2BIG) {
 #ifndef SUPPRESS_WARNINGS
                 std::cerr << "Warning: iconv: "
Index: src/tags.cpp
===================================================================
--- src/tags.cpp	(revision 2002)
+++ src/tags.cpp	(working copy)
@@ -2515,18 +2515,9 @@
         return os;
     }
 
-    // Todo: Implement this properly
     std::ostream& print0x9286(std::ostream& os, const Value& value, const ExifData*)
     {
-        if (value.size() > 8) {
-            DataBuf buf(value.size());
-            value.copy(buf.pData_, bigEndian);
-            // Hack: Skip the leading 8-Byte character code, truncate
-            // trailing '\0's and let the stream take care of the remainder
-            std::string userComment(reinterpret_cast<char*>(buf.pData_) + 8, buf.size_ - 8);
-            std::string::size_type pos = userComment.find_last_not_of('\0');
-            os << userComment.substr(0, pos + 1);
-        }
+		os << dynamic_cast<const CommentValue*> (&value)->value_;
         return os;
     }
 
Index: test/conversions.sh
===================================================================
--- test/conversions.sh	(revision 1997)
+++ test/conversions.sh	(working copy)
@@ -217,7 +217,7 @@
 
 # ----------------------------------------------------------------------
 # Evaluate results
-cat $results | sed 's/\x0d$//' > $results-stripped
+cat $results | sed 's/\x0d$//' | sed 's/\x1b/$/g' > $results-stripped
 diff -q $results-stripped $good
 rc=$?
 if [ $rc -eq 0 ] ; then
Index: test/data/exiv2-bug662.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: test\data\exiv2-bug662.jpg
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: test/exifcomment-encoding-test.sh
===================================================================
--- test/exifcomment-encoding-test.sh	(revision 0)
+++ test/exifcomment-encoding-test.sh	(revision 0)
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Test driver for exiv2 Exif.Photo.UserComment character encoding tests
+scriptdir=`dirname $0`
+cd $scriptdir
+exiv2="../src/exiv2"
+
+# Function takes two parameters
+#
+# 1. A exiv2 comment spec
+# 2. The expected exiv2 hex dump of the UserComment value
+#
+function writeComment {
+    cp ./data/exiv2-bug662.jpg ./tmp/exiv2-bug662.jpg
+    $exiv2 mo "-Mset Exif.Photo.UserComment $1" ./tmp/exiv2-bug662.jpg
+    res=`$exiv2 pr -PEnh ./tmp/exiv2-bug662.jpg | grep --after-context=200 UserComment`
+
+    # remove newlines and the tag name
+    res=`echo $res | colrm 1 12 | sed -e 's/"//g'`
+    if [ "$res" != "$2" ] ; then
+        echo "Expected:"
+        echo $2
+        echo "Got:"
+        echo $res
+        return 1
+    fi
+}
+
+writeComment "charset=Ascii An ascii comment" "0000 41 53 43 49 49 00 00 00 41 6e 20 61 73 63 69 69 ASCII...An ascii 0010 20 63 6f 6d 6d 65 6e 74 comment"
+writeComment "charset=Ascii A\\nnewline" "0000 41 53 43 49 49 00 00 00 41 0a 6e 65 77 6c 69 6e ASCII...A.newlin 0010 65 e"
+writeComment "charset=Unicode A Unicode comment" "0000 55 4e 49 43 4f 44 45 00 41 00 20 00 55 00 6e 00 UNICODE.A. .U.n. 0010 69 00 63 00 6f 00 64 00 65 00 20 00 63 00 6f 00 i.c.o.d.e. .c.o. 0020 6d 00 6d 00 65 00 6e 00 74 00 m.m.e.n.t."
+writeComment "charset=Unicode \\u01c4" "0000 55 4e 49 43 4f 44 45 00 c4 01 UNICODE..."
+writeComment "charset=Unicode A\\u01c4C" "0000 55 4e 49 43 4f 44 45 00 41 00 c4 01 43 00 UNICODE.A...C."
+writeComment "charset=Unicode With\\nNewline" "0000 55 4e 49 43 4f 44 45 00 57 00 69 00 74 00 68 00 UNICODE.W.i.t.h. 0010 0a 00 4e 00 65 00 77 00 6c 00 69 00 6e 00 65 00 ..N.e.w.l.i.n.e."
+writeComment "charset=Unicode With\\tTab" "0000 55 4e 49 43 4f 44 45 00 57 00 69 00 74 00 68 00 UNICODE.W.i.t.h. 0010 09 00 54 00 61 00 62 00 ..T.a.b."
+
+# Test invalid escape sequences
+writeComment "charset=Unicode \\ugggg" "0000 55 4e 49 43 4f 44 45 00 5c 00 75 00 67 00 67 00 UNICODE.\.u.g.g. 0010 67 00 67 00 g.g."
Index: test/Makefile
===================================================================
--- test/Makefile	(revision 1997)
+++ test/Makefile	(working copy)
@@ -61,6 +61,7 @@
         bugfixes-test.sh  \
         exifdata-test.sh  \
         exiv2-test.sh     \
+        exifcomment-encoding-test.sh \
         imagetest.sh      \
         iotest.sh         \
         iptctest.sh       \
