sw/qa/extras/ww8export/data/tdf142840.odt |binary sw/qa/extras/ww8export/ww8export3.cxx | 17 +++++++++++++++++ sw/source/filter/ww8/wrtw8nds.cxx | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-)
New commits: commit f2bf1cc2a9a4a09ec16900e91949e1669963c392 Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Fri Apr 29 11:10:48 2022 +0300 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Thu May 12 11:21:14 2022 +0200 tdf#142840: doc export: use BookmarkToWord() for hyperlinks Inernal hyperlinks to bookmarks should not contain spaces. This is not required for RTF or DOC: MS Word is okay with spaces there (unlike in DOCX). But since we are replacing spaces in bookmark names we should do this also in links to these bookmarks. Change-Id: I7a3e530817572ed53032c2be1ad96f8e8498bac3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133590 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> (cherry picked from commit d45315c8eb91862958b29ead09cec58e03a80096) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134177 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/ww8export/data/tdf142840.odt b/sw/qa/extras/ww8export/data/tdf142840.odt new file mode 100644 index 000000000000..27af4cdb5e6a Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf142840.odt differ diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 8e894c711457..330fb8b6bb2c 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -988,6 +988,23 @@ DECLARE_WW8EXPORT_TEST(testTdf136814, "tdf136814.odt") } +DECLARE_WW8EXPORT_TEST(testTdf142840, "tdf142840.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); + + // Ensure space are replaced by underscore in bookmark name (it was working before, but ensure this) + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xBookmarksByIdx->getCount()); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Chapter_1")); + CPPUNIT_ASSERT(!xBookmarksByName->hasByName("Chapter 1")); + + // And hyperlink is referring bookmark with underscore also (this was broken) + CPPUNIT_ASSERT_EQUAL(OUString("#Chapter_1"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 6081ab30af1d..ff23fc6fa9c1 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -1028,8 +1028,11 @@ bool WW8AttributeOutput::AnalyzeURL( const OUString& rUrl, const OUString& rTarg if ( !sURL.isEmpty() ) sURL = URIHelper::simpleNormalizedMakeRelative( m_rWW8Export.GetWriter().GetBaseURL(), sURL ); - if ( bBookMarkOnly ) - sURL = FieldString( ww::eHYPERLINK ); + if (bBookMarkOnly) + { + sURL = FieldString(ww::eHYPERLINK); + *pMark = BookmarkToWord(*pMark); + } else sURL = FieldString( ww::eHYPERLINK ) + "\"" + sURL + "\"";