diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2017-09-05 21:30:06 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-09-07 15:03:08 +0200 |
commit | aa3c0ddc61726f9e2e927e08966acd63a3fcf968 (patch) | |
tree | 23b2da173dd7ff3d9a407345e120d83ffa957960 | |
parent | e55ee82f519064319dddcd3dc4553c6580dcd93a (diff) |
tdf#103090 replace spaces by underscore in bookmark names for DOCX.
Bookmarks containing spaces are incorrectly interpreted by MS Word,
so spaces are replaced in bookmark names and bookmark references
in fields.
Change-Id: I4e23c6b8740b54e94a1ec7e3385cffbe3ba01709
Reviewed-on: https://gerrit.libreoffice.org/41954
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf103090.odt | bin | 0 -> 8845 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 22 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 30 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 3 |
5 files changed, 39 insertions, 22 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf103090.odt b/sw/qa/extras/ooxmlexport/data/tdf103090.odt Binary files differnew file mode 100644 index 000000000000..d264f255abb7 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf103090.odt diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 930cbdc41b4f..5f45cbcc7109 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -1049,6 +1049,28 @@ DECLARE_OOXMLEXPORT_TEST(tdf112169, "tdf112169.odt") // LO crashed while export because of character background color handling } +DECLARE_OOXMLEXPORT_TEST(testTdf103090, "tdf103090.odt") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; + + // Get bookmark name + OUString bookmarkName = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:bookmarkStart", "name"); + + // Ensure that name has no spaces + CPPUNIT_ASSERT(bookmarkName.indexOf(" ") < 0); + + // Get PAGEREF field + OUString fieldName = getXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText"); + + // Ensure that PAGEREF field refers exactly our bookmark + OUString expectedFieldName(" PAGEREF "); + expectedFieldName += bookmarkName; + expectedFieldName += " \\h "; + CPPUNIT_ASSERT_EQUAL(expectedFieldName, fieldName); +} + 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 f1413e5f62d7..365db5e55728 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1374,14 +1374,13 @@ void DocxAttributeOutput::EndRun() void DocxAttributeOutput::DoWriteBookmarks() { // Write the start bookmarks - for ( std::vector< OString >::const_iterator it = m_rBookmarksStart.begin(), end = m_rBookmarksStart.end(); - it != end; ++it ) + for ( const auto & it : m_rBookmarksStart ) { - const OString& rName = *it; + OString rName = OUStringToOString( BookmarkToWord( it ), RTL_TEXTENCODING_UTF8 ).getStr(); // Output the bookmark const sal_Int32 nId = m_nNextBookmarkId++; - m_rOpenedBookmarksIds[rName] = nId; + m_rOpenedBookmarksIds[it] = nId; m_pSerializer->singleElementNS( XML_w, XML_bookmarkStart, FSNS( XML_w, XML_id ), OString::number( nId ).getStr( ), FSNS( XML_w, XML_name ), rName.getStr(), @@ -1391,20 +1390,17 @@ void DocxAttributeOutput::DoWriteBookmarks() m_rBookmarksStart.clear(); // export the end bookmarks - for ( std::vector< OString >::const_iterator it = m_rBookmarksEnd.begin(), end = m_rBookmarksEnd.end(); - it != end; ++it ) + for ( const auto & it : m_rBookmarksEnd ) { - const OString& rName = *it; - // Get the id of the bookmark - std::map< OString, sal_Int32 >::iterator pPos = m_rOpenedBookmarksIds.find( rName ); - if ( pPos != m_rOpenedBookmarksIds.end( ) ) + auto pPos = m_rOpenedBookmarksIds.find(it); + if ( pPos != m_rOpenedBookmarksIds.end() ) { const sal_Int32 nId = ( *pPos ).second; m_pSerializer->singleElementNS( XML_w, XML_bookmarkEnd, - FSNS( XML_w, XML_id ), OString::number( nId ).getStr( ), + FSNS( XML_w, XML_id ), OString::number( nId ).getStr(), FSEND ); - m_rOpenedBookmarksIds.erase( rName ); + m_rOpenedBookmarksIds.erase( it ); } } m_rBookmarksEnd.clear(); @@ -6988,17 +6984,15 @@ void DocxAttributeOutput::WriteFormData_Impl( const ::sw::mark::IFieldmark& rFie void DocxAttributeOutput::WriteBookmarks_Impl( std::vector< OUString >& rStarts, std::vector< OUString >& rEnds ) { - for ( std::vector< OUString >::const_iterator it = rStarts.begin(), end = rStarts.end(); it != end; ++it ) + for ( const auto & it : rStarts ) { - OString rName = OUStringToOString( *it, RTL_TEXTENCODING_UTF8 ).getStr( ); - m_rBookmarksStart.push_back( rName ); + m_rBookmarksStart.push_back( it ); } rStarts.clear(); - for ( std::vector< OUString >::const_iterator it = rEnds.begin(), end = rEnds.end(); it != end; ++it ) + for ( const auto & it : rEnds ) { - OString rName = OUStringToOString( *it, RTL_TEXTENCODING_UTF8 ).getStr( ); - m_rBookmarksEnd.push_back( rName ); + m_rBookmarksEnd.push_back( it ); } rEnds.clear(); } diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 1a32aec81824..53c05ea2f65c 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -773,15 +773,15 @@ private: sal_Int32 m_nNextAnnotationMarkId; /// Bookmarks to output - std::vector<OString> m_rBookmarksStart; - std::vector<OString> m_rBookmarksEnd; + std::vector<OUString> m_rBookmarksStart; + std::vector<OUString> m_rBookmarksEnd; /// Annotation marks to output std::vector<OString> m_rAnnotationMarksStart; std::vector<OString> m_rAnnotationMarksEnd; /// Maps of the bookmarks ids - std::map<OString, sal_Int32> m_rOpenedBookmarksIds; + std::map<OUString, sal_Int32> m_rOpenedBookmarksIds; /// Name of the last opened bookmark. OString m_sLastOpenedBookmark; diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index bc536d49c876..4c99f18b1d53 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -1118,7 +1118,8 @@ bool WW8AttributeOutput::EndURL(bool const) OUString BookmarkToWord(const OUString &rBookmark) { - OUString sRet(INetURLObject::encode(rBookmark, + OUString sRet(INetURLObject::encode( + rBookmark.replace(' ', '_'), // Spaces are prohibited in bookmark name INetURLObject::PART_REL_SEGMENT_EXTRA, INetURLObject::EncodeMechanism::All, RTL_TEXTENCODING_ASCII_US)); return TruncateBookmark(sRet); |