diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx index 944a4dd5b25f..faed14065082 100644 --- a/comphelper/source/container/embeddedobjectcontainer.cxx +++ b/comphelper/source/container/embeddedobjectcontainer.cxx @@ -931,6 +931,14 @@ bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed } OUString aTempName, aMediaType; + /* Do not create a new name for a removed object, in the pImpl->mpTempObjectContainer, + because the original m_aEntryName of xObj will be overwritten by InsertEmbeddedObject(), + so uno::Reference < embed::XEmbeddedObject >& xObj will misbehave in + EmbeddedObjectContainer::StoreAsChildren and SfxObjectShell::SaveCompletedChildren + and will throw an exception because of objects with the same names! */ + if( !pImpl->mpTempObjectContainer->HasEmbeddedObject(aName) ) + aTempName = aName; + pImpl->mpTempObjectContainer->InsertEmbeddedObject( xObj, aTempName ); uno::Reference < io::XInputStream > xStream = GetGraphicStream( xObj, &aMediaType ); diff --git a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng index 486471a317d5..9167044ca87e 100644 --- a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng +++ b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng @@ -2472,4 +2472,13 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. + + + + + + + + + diff --git a/sw/qa/extras/odfexport/data/tdf134987.docx b/sw/qa/extras/odfexport/data/tdf134987.docx new file mode 100644 index 000000000000..c828bf442e1c Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf134987.docx differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 264edddea196..08166b3c2ccb 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -778,6 +779,58 @@ DECLARE_ODFEXPORT_TEST(testFdo58949, "fdo58949.docx") CPPUNIT_ASSERT_EQUAL(3, nMatches); } +DECLARE_ODFEXPORT_TEST(testTdf134987, "tdf134987.docx") +{ + uno::Reference xTEOSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xAccess(xTEOSupplier->getEmbeddedObjects()); + uno::Sequence aSeq(xAccess->getElementNames()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aSeq.getLength()); + + OUString aMediaType; + // checking first object (formula) + { + uno::Reference xEOSupplier(xAccess->getByName("1"), uno::UNO_QUERY); + uno::Reference xObj(xEOSupplier->getEmbeddedObject()); + CPPUNIT_ASSERT(xObj.is()); + + uno::Reference xSBDoc(xObj, uno::UNO_QUERY); + uno::Reference xStorage(xSBDoc->getDocumentStorage()); + CPPUNIT_ASSERT(xStorage.is()); + + uno::Reference< beans::XPropertySet > xStorProps(xStorage, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xStorProps->getPropertyValue("MediaType") >>= aMediaType); + CPPUNIT_ASSERT(aMediaType.equalsIgnoreAsciiCase(MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII)); + } + // checking second object (chart) + { + uno::Reference xEOSupplier(xAccess->getByName("2"), uno::UNO_QUERY); + uno::Reference xObj(xEOSupplier->getEmbeddedObject()); + CPPUNIT_ASSERT(xObj.is()); + + uno::Reference xSBDoc(xObj, uno::UNO_QUERY); + uno::Reference xStorage(xSBDoc->getDocumentStorage()); + CPPUNIT_ASSERT(xStorage.is()); + + uno::Reference< beans::XPropertySet > xStorProps(xStorage, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xStorProps->getPropertyValue("MediaType") >>= aMediaType); + CPPUNIT_ASSERT(aMediaType.equalsIgnoreAsciiCase(MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII)); + } + // checking third object (chart) + { + uno::Reference xEOSupplier(xAccess->getByName("3"), uno::UNO_QUERY); + uno::Reference xObj(xEOSupplier->getEmbeddedObject()); + CPPUNIT_ASSERT(xObj.is()); + + uno::Reference xSBDoc(xObj, uno::UNO_QUERY); + uno::Reference xStorage(xSBDoc->getDocumentStorage()); + CPPUNIT_ASSERT(xStorage.is()); + + uno::Reference< beans::XPropertySet > xStorProps(xStorage, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xStorProps->getPropertyValue("MediaType") >>= aMediaType); + CPPUNIT_ASSERT(aMediaType.equalsIgnoreAsciiCase(MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII)); + } +} + DECLARE_ODFEXPORT_TEST(testStylePageNumber, "ooo321_stylepagenumber.odt") { CPPUNIT_ASSERT_EQUAL(5, getPages());