Project

General

Profile

Bug #662 » exiv2-exifcomment-unicode.patch

Leo Sutic, 12 Jan 2010 10:09

View differences:

src/actions.cpp (working copy)
625 625
                && (   md.typeId() == Exiv2::undefined
626 626
                    || md.typeId() == Exiv2::unsignedByte
627 627
                    || md.typeId() == Exiv2::signedByte)
628
                && md.size() > 100) {
628
                && md.size() > 128) {
629 629
                std::cout << _("(Binary value suppressed)") << std::endl;
630 630
                return;
631 631
            }
......
638 638
                && (   md.typeId() == Exiv2::undefined
639 639
                    || md.typeId() == Exiv2::unsignedByte
640 640
                    || md.typeId() == Exiv2::signedByte)
641
                && md.size() > 100) {
641
                && md.size() > 128) {
642 642
                std::cout << _("(Binary value suppressed)") << std::endl;
643 643
                return;
644 644
            }
......
651 651
                && (   md.typeId() == Exiv2::undefined
652 652
                    || md.typeId() == Exiv2::unsignedByte
653 653
                    || md.typeId() == Exiv2::signedByte)
654
                && md.size() > 100) {
654
                && md.size() > 128) {
655 655
                std::cout << _("(Binary value suppressed)") << std::endl;
656 656
                return;
657 657
            }
src/convert.cpp (working copy)
508 508
            return;
509 509
        }
510 510
        // Todo: Convert to UTF-8 if necessary
511
		
511 512
        (*xmpData_)[to] = cv->comment();
512 513
        if (erase_) exifData_->erase(pos);
513 514
    }
......
1325 1326
        std::string outstr;
1326 1327
        EXV_ICONV_CONST char *inptr = const_cast<char *>(str.c_str());
1327 1328
        size_t inbytesleft = str.length();
1328
        int outbytesProduced = 0;
1329

  
1329 1330
        while (inbytesleft) {
1330 1331
            char outbuf[100];
1331 1332
            char *outptr = outbuf;
......
1335 1336
                              &inbytesleft,
1336 1337
                              &outptr,
1337 1338
                              &outbytesleft);
1338
            outbytesProduced += sizeof(outbuf) - 1 - outbytesleft;
1339

  
1340
			int outbytesProduced = sizeof(outbuf) - 1 - outbytesleft;
1339 1341
            if (rc == size_t(-1) && errno != E2BIG) {
1340 1342
#ifndef SUPPRESS_WARNINGS
1341 1343
                std::cerr << "Warning: iconv: "
src/tags.cpp (working copy)
2515 2515
        return os;
2516 2516
    }
2517 2517

  
2518
    // Todo: Implement this properly
2519 2518
    std::ostream& print0x9286(std::ostream& os, const Value& value, const ExifData*)
2520 2519
    {
2521
        if (value.size() > 8) {
2522
            DataBuf buf(value.size());
2523
            value.copy(buf.pData_, bigEndian);
2524
            // Hack: Skip the leading 8-Byte character code, truncate
2525
            // trailing '\0's and let the stream take care of the remainder
2526
            std::string userComment(reinterpret_cast<char*>(buf.pData_) + 8, buf.size_ - 8);
2527
            std::string::size_type pos = userComment.find_last_not_of('\0');
2528
            os << userComment.substr(0, pos + 1);
2529
        }
2520
		os << dynamic_cast<const CommentValue*> (&value)->value_;
2530 2521
        return os;
2531 2522
    }
2532 2523

  
test/conversions.sh (working copy)
217 217

  
218 218
# ----------------------------------------------------------------------
219 219
# Evaluate results
220
cat $results | sed 's/\x0d$//' > $results-stripped
220
cat $results | sed 's/\x0d$//' | sed 's/\x1b/$/g' > $results-stripped
221 221
diff -q $results-stripped $good
222 222
rc=$?
223 223
if [ $rc -eq 0 ] ; then
test/exifcomment-encoding-test.sh (revision 0)
1
#! /bin/sh
2
# Test driver for exiv2 Exif.Photo.UserComment character encoding tests
3
scriptdir=`dirname $0`
4
cd $scriptdir
5
exiv2="../src/exiv2"
6

  
7
# Function takes two parameters
8
#
9
# 1. A exiv2 comment spec
10
# 2. The expected exiv2 hex dump of the UserComment value
11
#
12
function writeComment {
13
    cp ./data/exiv2-bug662.jpg ./tmp/exiv2-bug662.jpg
14
    $exiv2 mo "-Mset Exif.Photo.UserComment $1" ./tmp/exiv2-bug662.jpg
15
    res=`$exiv2 pr -PEnh ./tmp/exiv2-bug662.jpg | grep --after-context=200 UserComment`
16

  
17
    # remove newlines and the tag name
18
    res=`echo $res | colrm 1 12 | sed -e 's/"//g'`
19
    if [ "$res" != "$2" ] ; then
20
        echo "Expected:"
21
        echo $2
22
        echo "Got:"
23
        echo $res
24
        return 1
25
    fi
26
}
27

  
28
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"
29
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"
30
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."
31
writeComment "charset=Unicode \\u01c4" "0000 55 4e 49 43 4f 44 45 00 c4 01 UNICODE..."
32
writeComment "charset=Unicode A\\u01c4C" "0000 55 4e 49 43 4f 44 45 00 41 00 c4 01 43 00 UNICODE.A...C."
33
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."
34
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."
35

  
36
# Test invalid escape sequences
37
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."
test/Makefile (working copy)
61 61
        bugfixes-test.sh  \
62 62
        exifdata-test.sh  \
63 63
        exiv2-test.sh     \
64
        exifcomment-encoding-test.sh \
64 65
        imagetest.sh      \
65 66
        iotest.sh         \
66 67
        iptctest.sh       \
(5-5/5)