sw/qa/extras/htmlimport/data/ole-data2.xhtml | 12 ++++++++++++ sw/qa/extras/htmlimport/htmlimport.cxx | 25 +++++++++++++++++++++++++ sw/source/filter/html/htmlgrin.cxx | 1 + 3 files changed, 38 insertions(+)
New commits: commit 47fa0fbb17bbe4f3edda9ad1563225a488bfb8a7 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Aug 17 10:32:16 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Aug 18 15:50:39 2022 +0200 sw XHTML import: fix unexpected link on image The trouble was that once an image got a pending link applied, the remaining images also got that link in case they didn't have an own link. This was a problem since commit 56769d3982e6afb075cb6d833662f066437fab6a (sw XHTML import: handle non-image, non-RTF objects as clickable images, 2022-05-24), the pending URL is not updated after it's applied. Fix the problem by clearing the pending URL, since we know that one pending URL is always applied just once. (cherry picked from commit ee3ebda2be3965584d12b52c007fb047d624b64c) Change-Id: I0a363330fbcc1dec95f90f56dc7c420249769e2a diff --git a/sw/qa/extras/htmlimport/data/ole-data2.xhtml b/sw/qa/extras/htmlimport/data/ole-data2.xhtml new file mode 100644 index 000000000000..0eb180e6ca63 --- /dev/null +++ b/sw/qa/extras/htmlimport/data/ole-data2.xhtml @@ -0,0 +1,12 @@ +<reqif-xhtml:div> +<reqif-xhtml:p> +<reqif-xhtml:object data="data.ole" type="application/octet-stream"> + <reqif-xhtml:object data="ole2.png" type="image/png"></reqif-xhtml:object> +</reqif-xhtml:object> +</reqif-xhtml:p> +<reqif-xhtml:p> +<reqif-xhtml:object data="data.gif" type="image/gif"> + <reqif-xhtml:object data="ole2.png" type="image/png"></reqif-xhtml:object> +</reqif-xhtml:object> +</reqif-xhtml:p> +</reqif-xhtml:div> diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 326af44fb298..b3b47c06f9cb 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -516,6 +516,31 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData) CPPUNIT_ASSERT(getProperty<OUString>(xShape, "HyperLinkURL").endsWith("/data.ole")); } +CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData2) +{ + // Given an XHTML with 2 objects: the first has a link, the second does not have: + uno::Sequence<beans::PropertyValue> aLoadProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-data2.xhtml"; + + // When loading the document: + mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + + // Then make sure that the second image doesn't have a link set: + uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xObjects(xSupplier->getGraphicObjects(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xObjects->getCount()); + uno::Reference<css::drawing::XShape> xShape = getShape(1); + CPPUNIT_ASSERT(getProperty<OUString>(xShape, "HyperLinkURL").endsWith("/data.ole")); + xShape = getShape(2); + // Without the accompanying fix in place, this test would have failed, the link from the 1st + // image leaked to the 2nd image. + CPPUNIT_ASSERT(getProperty<OUString>(xShape, "HyperLinkURL").isEmpty()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 2a8e8c46dc13..b1bd3d445265 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -871,6 +871,7 @@ IMAGE_SETEVENT: // image. SwFormatURL aURL(pFlyFormat->GetURL()); aURL.SetURL(m_aEmbedURL, bIsMap); + m_aEmbedURL.clear(); pFlyFormat->SetFormatAttr(aURL); }