diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index 7ea3f67a..f6dea4c7 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -209,13 +209,9 @@ namespace Exiv2 { */ int add(const Xmpdatum& xmpdatum); /*! - @brief Delete the Xmpdatum at iterator position pos, return the - position of the next Xmpdatum. - - @note Iterators into the metadata, including pos, are potentially - invalidated by this call. + @brief Delete the Xmpdatum at iterator position pos and update pos */ - iterator erase(iterator pos); + void erase(iterator& pos); //! Delete all Xmpdatum instances resulting in an empty container. void clear(); //! Sort metadata by key diff --git a/src/xmp.cpp b/src/xmp.cpp index 1d636290..87c441c7 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -382,11 +382,21 @@ namespace Exiv2 { return xmpMetadata_.end(); } - XmpData::iterator XmpData::erase(XmpData::iterator pos) - { - return xmpMetadata_.erase(pos); + void XmpData::erase(XmpData::iterator& pos) + { + // https://github.com/Exiv2/exiv2/issues/521 + // delete 'children' of XMP composites (XmpSeq and XmpBag) + std::string key = pos->key(); + while ( pos != end() ) { + if ( pos->key().find(key)==0 ) { + xmpMetadata_.erase(pos); + } else { + break ; + } + } } + bool XmpParser::initialized_ = false; XmpParser::XmpLockFct XmpParser::xmpLockFct_ = 0; void* XmpParser::pLockData_ = 0; diff --git a/test/data/conversions.out b/test/data/conversions.out index 5f766040..535dfba4 100644 --- a/test/data/conversions.out +++ b/test/data/conversions.out @@ -149,18 +149,18 @@ Iptc.Envelope.CharacterSet String 3 %G Testcase 15 =========== +Xmp.xmp.ModifyDate XmpText 20 2015-04-17T18:10:22Z Xmp.exif.ExifVersion XmpText 4 2.21 Xmp.exif.GPSVersionID XmpText 7 2.2.0.1 Xmp.exif.GPSLatitude XmpText 12 3,8.4955752N Xmp.exif.GPSTimeStamp XmpText 29 2003-12-14T01:02:00.999999999 +Xmp.exif.ComponentsConfiguration XmpSeq 4 YCbCr Xmp.exif.Flash XmpText 0 type="Struct" Xmp.exif.Flash/exif:Fired XmpText 4 True Xmp.exif.Flash/exif:Return XmpText 1 0 Xmp.exif.Flash/exif:Mode XmpText 1 1 Xmp.exif.Flash/exif:Function XmpText 5 False Xmp.exif.Flash/exif:RedEyeMode XmpText 4 True -Xmp.exif.ComponentsConfiguration XmpSeq 4 YCbCr -Xmp.xmp.ModifyDate XmpText 20 2015-04-17T18:10:22Z Xmp.photoshop.DateCreated XmpText 29 2003-12-14T12:01:44.999999999 Exif.Image.DateTime Ascii 20 2015:04:18 02:10:22 Exif.Image.ExifTag Long 1 70