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.
Change-Id: I0a363330fbcc1dec95f90f56dc7c420249769e2a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138409
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
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 0000000..0eb180e
--- /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 866477d..82b89f5 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -563,6 +563,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 5a71743..d1e6ebb 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -877,6 +877,7 @@ IMAGE_SETEVENT:
// image.
SwFormatURL aURL(pFlyFormat->GetURL());
aURL.SetURL(m_aEmbedURL, bIsMap);
m_aEmbedURL.clear();
pFlyFormat->SetFormatAttr(aURL);
}