Bug 65955 - FILESAVE: DOCX export: bookmark at end of paragraph not exported correctly
Summary: FILESAVE: DOCX export: bookmark at end of paragraph not exported correctly
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: filters and storage (show other bugs)
Version:
(earliest affected)
4.0.4.2 release
Hardware: All All
: medium normal
Assignee: Szymon Kłos
URL:
Whiteboard: target:6.0.0 target:6.1.0 target:6.0.0.1
Keywords: filter:docx
Depends on:
Blocks: DOCX
  Show dependency treegraph
 
Reported: 2013-06-20 07:32 UTC by Christoph Lutz
Modified: 2018-01-15 13:54 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Lutz 2013-06-20 07:32:10 UTC
If there is a bookmark at the end of a paragraph, the bookmark is not exported correctly to DOCX. 

Two types of errors are possible (but I think they have the same cause):

a) if there is a collapsed bookmark (at paragraph end), it is exported to the beginning of the paragraph

b) if there is a bookmark that extends over contents (at paragraph end), it is collapsed *before* the content.

How to reproduce:
1) create a new Document in Writer
2) add two paragraphs with content "foo" (first par) and "bar" (second par)
3) place the curser after the "o" of "foo"
4) insert a bookmark "a"
5) mark the content "r" in "bar"
6) insert a bookmark "b"
7) save the file as DOCX (Microsoft Word 2007/2010 XML)
8) look at the generated word/document.xml (inside the docx file)

you will find the following RESULT (first paragraph = case a):

<w:p>
  <w:pPr>
    <w:pStyle w:val="style0"/>
  </w:pPr>
  <w:bookmarkStart w:id="0" w:name="a"/>
  <w:bookmarkEnd w:id="0"/>
  <w:r>
    <w:rPr/>
    <w:t>Foo</w:t>
  </w:r>
</w:p>

where the EXPECTED result for the first paragraph (case a) is:

<w:p>
  <w:pPr>
    <w:pStyle w:val="style0"/>
  </w:pPr>
  <w:r>
    <w:rPr/>
    <w:t>Foo</w:t>
  </w:r>
  <w:bookmarkStart w:id="0" w:name="a"/>
  <w:bookmarkEnd w:id="0"/>
</w:p>

And the RESULT for the second paragraph (case b) is:

<w:p>
  <w:pPr>
    <w:pStyle w:val="style0"/>
  </w:pPr>
  <w:r>
    <w:rPr/>
    <w:t>ba</w:t>
  </w:r>
  <w:bookmarkStart w:id="1" w:name="b"/>
  <w:bookmarkEnd w:id="1"/>
  <w:r>
    <w:rPr/>
    <w:t>r</w:t>
  </w:r>
</w:p>

where the EXPECTED result for the second paragraph (case b) is:  

<w:p>
  <w:pPr>
    <w:pStyle w:val="style0"/>
  </w:pPr>
  <w:r>
    <w:rPr/>
    <w:t>ba</w:t>
  </w:r>
  <w:bookmarkStart w:id="1" w:name="b"/>
  <w:r>
    <w:rPr/>
    <w:t>r</w:t>
  </w:r>
  <w:bookmarkEnd w:id="1"/>
</w:p>

BTW: if the bookmark is in any other position within the paragraph, it is exported correctly. The bug only occurs if the bookmark is the last element in the paragraph.
Comment 1 Jorendc 2013-06-23 17:01:28 UTC
I can confirm this using Linux Mint 15 x64 with LibreOffice Version: 4.2.0.0.alpha0+ Build ID: 87c50e75633f31b54bfa1758cc0921ac53c6b418

It looks like it's even a bit more worse:

<w:p>
 <w:pPr>
  <w:pStyle w:val="style0"/>
  <w:rPr>
  </w:rPr>
 </w:pPr>
 <w:bookmarkStart w:id="0" w:name="a"/>
 <w:bookmarkEnd w:id="0"/>
 <w:r>
  <w:rPr>
  </w:rPr>
  <w:t>Foo</w:t>
 </w:r>
</w:p>

More in particular the added no-sense extra <w:rPr></w:rPr>

Kind regards,
Joren

Code pointer: http://opengrok.libreoffice.org/xref/core/sw/source/filter/ww8/docxattributeoutput.cxx#678
Comment 2 aurimas.dev 2014-03-01 07:28:55 UTC
One additional (but possibly related) case where the positioning of bookmark tags is incorrect appears to be when a bookmark spans two or more formatting elements.

Steps to reproduce:
1) create a new Document in Writer
2) add "foo bar" (as a single paragraph)
3) highlight "foo" and make it bold. highlight "bar" and make it italic
4) select the whole line (i.e. "foo bar") and add bookmark. Name it "test"
7) save the file as DOCX (Microsoft Word 2007/2010 XML)
8) look at the generated word/document.xml (inside the docx file)

Observed result (pPr section omitted):
<w:p>
  <w:bookmarkStart w:id="0" w:name="test" />
  <w:r>
    <w:rPr>
      <w:b />
      <w:bCs />
    </w:rPr>
    <w:t>foo</w:t>
  </w:r>
  <w:r>
    <w:rPr></w:rPr>
    <w:t xml:space="preserve"> </w:t>
  </w:r>
  <w:bookmarkEnd w:id="0" />
  <w:r>
    <w:rPr>
      <w:i />
      <w:iCs />
    </w:rPr>
    <w:t>bar</w:t>
  </w:r>
</w:p>

Expected result:
<w:p>
  <w:bookmarkStart w:id="0" w:name="test" />
  <w:r>
    <w:rPr>
      <w:b />
      <w:bCs />
    </w:rPr>
    <w:t>foo</w:t>
  </w:r>
  <w:r>
    <w:rPr></w:rPr>
    <w:t xml:space="preserve"> </w:t>
  </w:r>
  <w:r>
    <w:rPr>
      <w:i />
      <w:iCs />
    </w:rPr>
    <w:t>bar</w:t>
  </w:r>
  <w:bookmarkEnd w:id="0" />
</w:p>

It seems that no matter how many <w:r> elements the bookmark is supposed to encompass, it is always ended after the second one.
Comment 3 Joel Madero 2015-05-02 15:41:56 UTC Comment hidden (obsolete)
Comment 4 Andrey Skvortsov 2016-06-23 14:01:52 UTC
Reproduced in LO 5.1.4 (Linux amd64)
Comment 5 Commit Notification 2017-11-24 06:36:02 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=50915bababcf6b645fe3b57c265560a3cd0c6224

tdf#65955 DOCX: bookmarks at the end of paragraph

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2017-11-29 06:39:21 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=76f28863e7974da5a7280b3efa8a157c114ca03c

tdf#65955 Bookmarks on two paragraphs

It will be available in 6.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Commit Notification 2017-11-30 07:42:56 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "libreoffice-6-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=948626d46f755fd7c0b2da6b559b4c24f5590f67&h=libreoffice-6-0

tdf#65955 Bookmarks on two paragraphs

It will be available in 6.0.0.1.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.