sw: remove defensive programming bullshit in lcl_AssureFieldMarksSet

In CppunitTest_sw_ooxmlfieldexport testFdo81492 a TextFieldmark is
inserted at a position where already another TextFieldmark starts. The
defensively programmed lcl_AssureFieldMarksSet notices there is aleady a
dummy character at the start position, and does not insert another one,
but then the dummy character for the end position is inserted, moving
the start position index, which puts the start position behind another
bookmark.

So we end up with a field mark that has a end character but not a start
character and an un-sorted m_vAllMarks.

Change-Id: Icd15e83471e18f607eb41b2f7b0c2ce61c94ff9f
This commit is contained in:
Michael Stahl
2016-09-28 10:41:07 +02:00
parent 2bd8be10e2
commit bb069fe7b8
2 changed files with 10 additions and 22 deletions

View File

@@ -565,7 +565,7 @@ DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx")
{
if (xmlDocPtr pXmlDoc = parseExport())
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[5]/w:instrText", "ADDIN EN.CITE.DATA");
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:instrText", "ADDIN EN.CITE.DATA");
}
DECLARE_OOXMLEXPORT_TEST(testEditTime, "fdo81341.docx")

View File

@@ -73,11 +73,7 @@ namespace
io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, nullptr);
SwPosition start = pField->GetMarkStart();
SwTextNode const*const pStartTextNode = start.nNode.GetNode().GetTextNode();
sal_Unicode ch_start = 0;
if (pStartTextNode && (start.nContent.GetIndex() < pStartTextNode->GetText().getLength()))
ch_start = pStartTextNode->GetText()[start.nContent.GetIndex()];
if( ( ch_start != aStartMark ) && ( aEndMark != CH_TXT_ATR_FORMELEMENT ) )
if (aEndMark != CH_TXT_ATR_FORMELEMENT)
{
SwPaM aStartPaM(start);
io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(aStartMark));
@@ -88,14 +84,7 @@ namespace
}
SwPosition& rEnd = pField->GetMarkEnd();
SwTextNode const*const pEndTextNode = rEnd.nNode.GetNode().GetTextNode();
const sal_Int32 nEndPos = (rEnd == start || rEnd.nContent.GetIndex() == 0)
? rEnd.nContent.GetIndex()
: rEnd.nContent.GetIndex() - 1;
sal_Unicode ch_end = 0;
if ( pEndTextNode && ( nEndPos < pEndTextNode->GetText().getLength() ) )
ch_end = pEndTextNode->GetText()[nEndPos];
if ( aEndMark && ( ch_end != aEndMark ) )
if (aEndMark)
{
SwPaM aEndPaM(rEnd);
io_pDoc->getIDocumentContentOperations().InsertString(aEndPaM, OUString(aEndMark));
@@ -118,8 +107,9 @@ namespace
if( pStartTextNode )
ch_start = pStartTextNode->GetText()[rStart.nContent.GetIndex()];
if( ch_start == aStartMark )
if (aEndMark != CH_TXT_ATR_FORMELEMENT)
{
assert(ch_start == aStartMark);
SwPaM aStart(rStart, rStart);
++aStart.End()->nContent;
io_pDoc->getIDocumentContentOperations().DeleteRange(aStart);
@@ -133,13 +123,11 @@ namespace
sal_Unicode ch_end = 0;
if ( pEndTextNode )
ch_end = pEndTextNode->GetText()[nEndPos];
if ( ch_end == aEndMark )
{
assert(ch_end == aEndMark);
SwPaM aEnd(rEnd, rEnd);
if (aEnd.Start()->nContent > 0)
--aEnd.Start()->nContent;
io_pDoc->getIDocumentContentOperations().DeleteRange(aEnd);
}
io_pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_UI_REPLACE, nullptr);
};