tdf#127362 DOCX export: fix image hyperlink with space to bookmark target

Images as hyperlinks to internal bookmark targets didn't work after
export, because spaces were replaced only in bookmarks with underline
characters, now in hyperlinks, too.

Change-Id: I281b2cde276607aa93de92745cfa1ba887ba9976
Reviewed-on: https://gerrit.libreoffice.org/78782
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf127362.odt b/sw/qa/extras/ooxmlexport/data/tdf127362.odt
new file mode 100644
index 0000000..488f152
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf127362.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index b8c9f7a..dd059cd 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -729,6 +729,21 @@
    assertXPathNoAttribute(pXmlRels, "/rels:Relationships/rels:Relationship[@Target='#bookmark']", "TargetMode");
}

DECLARE_OOXMLEXPORT_TEST(testTdf127362, "tdf127362.odt")
{
    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
    if (!pXmlDoc)
        return;

    xmlDocPtr pXmlRels = parseExport("word/_rels/document.xml.rels");
    if (!pXmlRels)
        return;

    OUString bookmarkName = "#" + getXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:bookmarkStart", "name");
    OUString anchor = getXPath(pXmlRels, "/rels:Relationships/rels:Relationship[@Id='rId3']", "Target");
    CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 46c44a0..77f12ac 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4851,6 +4851,12 @@
        xPropSet->getPropertyValue("HyperLinkURL") >>= sURL;
        if(!sURL.isEmpty())
        {
            if (sURL.startsWith("#") && sURL.indexOf(' ') != -1 && !sURL.endsWith("|outline") && !sURL.endsWith("|table") &&
                !sURL.endsWith("|frame") && !sURL.endsWith("|graphic") && !sURL.endsWith("|ole") && !sURL.endsWith("|region"))
            {
                // Spaces are prohibited in bookmark name.
                sURL = sURL.replace(' ', '_');
            }
            sRelId = GetExport().GetFilter().addRelation( m_pSerializer->getOutputStream(),
                        oox::getRelationship(Relationship::HYPERLINK),
                        sURL, !sURL.startsWith("#") );