sw/qa/extras/htmlexport/data/link_with_target.fodt          |    9 ++++++
 sw/qa/extras/htmlexport/data/tdf160867_image_with_link.fodt |    4 +--
 sw/qa/extras/htmlexport/htmlexport.cxx                      |   16 ++++++++++++
 sw/source/filter/html/htmlatr.cxx                           |   15 ++++++-----
 sw/source/filter/html/htmlflywriter.cxx                     |    7 +++--
 5 files changed, 40 insertions(+), 11 deletions(-)

New commits:
commit 2d484bb9ad953cd9ae52cbfa70e4bde66769322d
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Dec 10 16:03:40 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Dec 10 17:59:45 2024 +0500

    ReqIF: avoid 'target' attribute in 'a' elements
    
    Change-Id: Iab34a18e2da766d30a2d6b5f5d8ed3855f3c8b8e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178207
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/htmlexport/data/link_with_target.fodt 
b/sw/qa/extras/htmlexport/data/link_with_target.fodt
new file mode 100644
index 000000000000..3be1cc31f120
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/link_with_target.fodt
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <text:p><text:a xlink:type="simple" xlink:href="http://www.example.org/"; 
office:target-frame-name="_blank">link</text:a></text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/htmlexport/data/tdf160867_image_with_link.fodt 
b/sw/qa/extras/htmlexport/data/tdf160867_image_with_link.fodt
index 43c35cdff13e..7bf886ab94ce 100644
--- a/sw/qa/extras/htmlexport/data/tdf160867_image_with_link.fodt
+++ b/sw/qa/extras/htmlexport/data/tdf160867_image_with_link.fodt
@@ -8,13 +8,13 @@
  </office:styles>
  <office:body>
   <office:text>
-   <text:p><draw:a xlink:type="simple" xlink:href="foo/bar"><draw:frame 
draw:style-name="Frame" draw:name="image1" svg:width="17cm" svg:height="25mm" 
style:rel-height="scale"><draw:image draw:mime-type="image/png">
+   <text:p><draw:a xlink:type="simple" xlink:href="foo/bar" 
office:target-frame-name="_blank"><draw:frame draw:style-name="Frame" 
draw:name="image1" svg:width="17cm" svg:height="25mm" 
style:rel-height="scale"><draw:image draw:mime-type="image/png">
        
<office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAAMSURBVBhXY/jPwAAAAwEBAGMkVdMAAAAASUVORK5C</office:binary-data>
       </draw:image>
      </draw:frame></draw:a>image1 with a hyperlink, and this text with <text:a 
xlink:type="simple" xlink:href="baz" text:style-name="Internet_20_link" 
text:visited-style-name="Visited_20_Internet_20_Link">another 
hyperlink</text:a></text:p>
    <text:p><draw:frame draw:style-name="Frame" draw:name="frame" 
svg:width="17cm">
      <draw:text-box fo:min-height="1pt">
-      <text:p><draw:a xlink:type="simple" xlink:href="foo/bar"><draw:frame 
draw:style-name="Frame" draw:name="image2" svg:width="17cm" 
svg:height="25mm"><draw:image draw:mime-type="image/png">
+      <text:p><draw:a xlink:type="simple" xlink:href="foo/bar" 
office:target-frame-name="_blank"><draw:frame draw:style-name="Frame" 
draw:name="image2" svg:width="17cm" svg:height="25mm"><draw:image 
draw:mime-type="image/png">
           
<office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAAMSURBVBhXY/jPwAAAAwEBAGMkVdMAAAAASUVORK5C</office:binary-data>
          </draw:image>
         </draw:frame></draw:a>image2 with a hyperlink, and this text with 
<text:a xlink:type="simple" xlink:href="baz" text:style-name="Internet_20_link" 
text:visited-style-name="Visited_20_Internet_20_Link">another 
hyperlink</text:a>, in a frame</text:p>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 993de1d44309..19e0d0c0d375 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -3101,6 +3101,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqIF_160867)
     assertXPath(pXmlDoc, 
"//reqif-xhtml:p[2]/reqif-xhtml:a/reqif-xhtml:object"_ostr);
     CPPUNIT_ASSERT(getXPath(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a"_ostr, 
"href"_ostr)
                        .endsWith("foo/bar"));
+    // There must be no 'target' attribute
+    assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a", 
"target");
 }
 
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_161979)
@@ -3427,6 +3429,20 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifNoTypeInUL)
     assertXPathNoAttribute(pXmlDoc, 
"//reqif-xhtml:ul/reqif-xhtml:li/reqif-xhtml:ul", "type");
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifNoTargetInA)
+{
+    // Given a document with a link with target:
+    createSwDoc("link_with_target.fodt");
+
+    // When exporting to XHTML:
+    ExportToReqif();
+
+    // Check that 'a' element has no 'target' attribute
+    xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile();
+    // Without the accompanying fix in place, this test would have failed
+    assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:a", "target");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index f298f93dc5b2..1c9ba0f62543 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -3084,13 +3084,16 @@ SwHTMLWriter& OutHTML_INetFormat( SwHTMLWriter& rWrt, 
const SwFormatINetFormat&
         sOut = "\""_ostr;
     }
 
-    const OUString& rTarget = rINetFormat.GetTargetFrame();
-    if( !rTarget.isEmpty() )
+    if (!rWrt.mbReqIF) // no target attribute for ReqIF
     {
-        sOut += " " OOO_STRING_SVTOOLS_HTML_O_target "=\"";
-        rWrt.Strm().WriteOString( sOut );
-        HTMLOutFuncs::Out_String( rWrt.Strm(), rTarget );
-        sOut = "\""_ostr;
+        const OUString& rTarget = rINetFormat.GetTargetFrame();
+        if (!rTarget.isEmpty())
+        {
+            sOut += " " OOO_STRING_SVTOOLS_HTML_O_target "=\"";
+            rWrt.Strm().WriteOString(sOut);
+            HTMLOutFuncs::Out_String(rWrt.Strm(), rTarget);
+            sOut = "\""_ostr;
+        }
     }
 
     if( !sRel.isEmpty() )
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 73c652496ece..042f0504016e 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1282,7 +1282,8 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, 
SwHTMLWriter& rWrt, const S
         {
             aMapURL = pURLItem->GetURL();
             aName = pURLItem->GetName();
-            aTarget = pURLItem->GetTargetFrameName();
+            if (!rWrt.mbReqIF) // no target attribute for ReqIF
+                aTarget = pURLItem->GetTargetFrameName();
         }
         else if (rWrt.mbReqIF && pAltImgMap)
         {
@@ -1293,8 +1294,8 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, 
SwHTMLWriter& rWrt, const S
                 {
                     aMapURL = pIMapObject->GetURL();
                     aName = pIMapObject->GetName();
-                    aTarget = pIMapObject->GetTarget();
-                    if (!aMapURL.isEmpty() || !aName.isEmpty() || 
!aTarget.isEmpty())
+                    // Don't read target for ReqIF
+                    if (!aMapURL.isEmpty() || !aName.isEmpty())
                         break;
                 }
             }

Reply via email to