Kaydet (Commit) 3c87d89b authored tarafından Vinaya Mandke's avatar Vinaya Mandke Kaydeden (comit) Miklos Vajna

fdo#78910 Hyperlink and Field start-end mismatch

Originally a Field began inside a hyperlink but ended after the hyperlink.
This causes the corruption in MS Word.

Incremented the field count if the field is added for the current new hyperlink.
Added another variable to store the Field-Count from previous hyperlink.

Added UT for the same.

Change-Id: Id3c3bee1c8ed9c0755f8fff7efd5d1c5662f2c82
Reviewed-on: https://gerrit.libreoffice.org/9421Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst b56c9aaa
......@@ -3486,6 +3486,18 @@ DECLARE_OOXMLEXPORT_TEST(testWordArtWithinDraingtool, "testWordArtWithinDraingto
assertXPath(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[4]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/wps:wsp[1]/wps:txbx[1]/w:txbxContent[1]",1);
}
DECLARE_OOXMLEXPORT_TEST(testFdo78910, "fdo78910.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
// This is to ensure that the fld starts and ends inside a hyperlink...
assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[1]/w:fldChar", "fldCharType", "begin" );
assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[5]/w:fldChar", "fldCharType", "end" );
}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -759,6 +759,13 @@ void DocxAttributeOutput::StartRun( const SwRedlineData* pRedlineData, bool /*bS
void DocxAttributeOutput::EndRun()
{
int nFieldsInPrevHyperlink = m_nFieldsInHyperlink;
// Reset m_nFieldsInHyperlink if a new hyperlink is about to start
if ( m_pHyperlinkAttrList )
{
m_nFieldsInHyperlink = 0;
}
// Write field starts
for ( std::vector<FieldInfos>::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); )
{
......@@ -767,6 +774,11 @@ void DocxAttributeOutput::EndRun()
{
StartField_Impl( *pIt );
if ( m_pHyperlinkAttrList )
{
m_nFieldsInHyperlink++;
}
// Remove the field from the stack if only the start has to be written
// Unknown fields sould be removed too
if ( !pIt->bClose || ( pIt->eType == ww::eUNKNOWN ) )
......@@ -791,7 +803,7 @@ void DocxAttributeOutput::EndRun()
{
if ( m_startedHyperlink )
{
for ( int i = 0; i < m_nFieldsInHyperlink; i++ )
for ( int i = 0; i < nFieldsInPrevHyperlink; i++ )
{
// If fields begin before hyperlink then
// it should end before hyperlink close
......@@ -836,7 +848,6 @@ void DocxAttributeOutput::EndRun()
m_pHyperlinkAttrList = NULL;
m_startedHyperlink = true;
m_nHyperLinkCount++;
m_nFieldsInHyperlink = 0;
}
// if there is some redlining in the document, output it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment