sw/qa/extras/ooxmlexport/data/tdf148026.fodt |   14 ++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx   |   12 ++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   10 ++++++++--
 3 files changed, 34 insertions(+), 2 deletions(-)

New commits:
commit ed77023797985e62e8f0af29326a61f55a65ae0a
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Wed Mar 1 10:09:02 2023 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Mar 9 16:46:36 2023 +0000

    tdf#148026 DOCX export: fix link with target frame and anchor
    
    Hyperlink with target frame and anchor didn't work after export.
    
    Change-Id: I84980e30d2e1d6d53cfe201cf4cac60354151aba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148041
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf148026.fodt 
b/sw/qa/extras/ooxmlexport/data/tdf148026.fodt
new file mode 100644
index 000000000000..80d958a6943c
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf148026.fodt
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+  <style:style style:name="Internet_20_link" style:display-name="Internet 
link" style:family="text">
+   <style:text-properties fo:color="#000080" loext:opacity="100%" 
fo:language="zxx" fo:country="none" style:text-underline-style="solid" 
style:text-underline-width="auto" style:text-underline-color="font-color" 
style:language-asian="zxx" style:country-asian="none" 
style:language-complex="zxx" style:country-complex="none"/>
+  </style:style>
+ </office:styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1"><text:a xlink:type="simple" 
xlink:href="https://bugs.documentfoundation.org/a#b"; 
office:target-frame-name="_self" xlink:show="replace" 
text:style-name="Internet_20_link" 
text:visited-style-name="Visited_20_Internet_20_Link"><text:span 
text:style-name="T1">https://bugs.documentfoundation.org/a#b _self 
frame</text:span></text:a> </text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 770ea9a89dec..b9432a32a47b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -579,6 +579,18 @@ CPPUNIT_TEST_FIXTURE(Test, 
testExportingUnknownStyleInRedline)
                 
"/w:document/w:body/w:p/w:pPr/w:pPrChange/w:pPr/w:pStyle[@w:val='UnknownStyle']");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf148026)
+{
+    loadAndReload("tdf148026.fodt");
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - In <>, XPath '//w:hyperlink' number of nodes is incorrect
+    // i.e. a HYPERLINK field was exported instead of the hyperlink XML 
element.
+    assertXPath(pXmlDoc, "//w:hyperlink", "tgtFrame", "_self");
+}
+
 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 45121566ec24..05efeafbd19b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3654,7 +3654,7 @@ bool DocxAttributeOutput::AnalyzeURL( const OUString& 
rUrl, const OUString& rTar
 {
     bool bBookMarkOnly = AttributeOutputBase::AnalyzeURL( rUrl, rTarget, 
pLinkURL, pMark );
 
-    if ( !pMark->isEmpty() )
+    if (!pMark->isEmpty() && (bBookMarkOnly || rTarget.isEmpty()))
     {
         OUString sURL = *pLinkURL;
 
@@ -3689,7 +3689,7 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, 
const OUString& rTarge
 
     m_hyperLinkAnchor = sMark;
 
-    if ( !sMark.isEmpty() && !bBookmarkOnly )
+    if (!sMark.isEmpty() && !bBookmarkOnly && rTarget.isEmpty())
     {
         m_rExport.OutputField( nullptr, ww::eHYPERLINK, sUrl );
     }
@@ -3705,6 +3705,12 @@ bool DocxAttributeOutput::StartURL( const OUString& 
rUrl, const OUString& rTarge
                         sUrl, true ), RTL_TEXTENCODING_UTF8 );
 
             m_pHyperlinkAttrList->add(FSNS(XML_r, XML_id), sId);
+            if (!sMark.isEmpty())
+            {
+                sMark = sMark.replace(' ', '_');
+                m_pHyperlinkAttrList->add(FSNS(XML_w, XML_anchor),
+                                          OUStringToOString(sMark, 
RTL_TEXTENCODING_UTF8));
+            }
         }
         else
         {

Reply via email to