msodumper/docrecord.py       |    4 +++-
 test/doc/bookmark-nested.doc |binary
 test/doc/test.py             |   13 +++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

New commits:
commit 8218b715ca1dc17bbb0dc48a513d55cdcfd5fbf5
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Tue Feb 4 13:54:28 2014 +0100

    PlcfBkl: don't assume PlcfBkf and PlcfBkl are entirely parallel
    
    This is true for a single entry, but for multiple entires they may not
    be parallel: the ibkl in PlcfBkf contains the index in the PlcfBkl.

diff --git a/msodumper/docrecord.py b/msodumper/docrecord.py
index a6e63c4..529a7bc 100644
--- a/msodumper/docrecord.py
+++ b/msodumper/docrecord.py
@@ -109,6 +109,7 @@ class PlcfBkf(DOCDirStream, PLC):
         self.pos = offset
         self.size = size
         self.aCP = []
+        self.aFBKF = []
 
     def dump(self):
         print '<plcfBkf type="PlcfBkf" offset="%d" size="%d bytes">' % 
(self.pos, self.size)
@@ -123,6 +124,7 @@ class PlcfBkf(DOCDirStream, PLC):
             # aFBKF
             aFBKF = FBKF(self, self.getOffset(self.pos, i))
             aFBKF.dump()
+            self.aFBKF.append(aFBKF)
             print '</aCP>'
         print '</plcfBkf>'
 
@@ -202,7 +204,7 @@ class PlcfBkl(DOCDirStream, PLC):
             # aCp
             end = self.getuInt32(pos = pos)
             print '<aCP index="%d" bookmarkEnd="%d">' % (i, end)
-            start = self.start.aCP[i]
+            start = self.start.aCP[self.start.aFBKF[i].ibkl]
             print '<transformed value="%s"/>' % 
self.quoteAttr(self.mainStream.retrieveCPs(start, end))
             pos += 4
             print '</aCP>'
diff --git a/test/doc/bookmark-nested.doc b/test/doc/bookmark-nested.doc
new file mode 100644
index 0000000..8cee8fa
Binary files /dev/null and b/test/doc/bookmark-nested.doc differ
diff --git a/test/doc/test.py b/test/doc/test.py
index 1812d53..ec3f815 100755
--- a/test/doc/test.py
+++ b/test/doc/test.py
@@ -137,6 +137,19 @@ class Test(unittest.TestCase):
         # The bookmark covers Hello
         self.assertEqual('Hello', 
bookmarkEnds[0].findall('transformed')[0].attrib['value'])
 
+    def test_bookmark_nested(self):
+        self.dump('bookmark-nested')
+
+        bookmarkStarts = 
self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBkf/plcfBkf/aCP')
+        bookmarkEnds = 
self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBkl/plcfBkl/aCP')
+        self.assertEqual(2, len(bookmarkStarts))
+        self.assertEqual(2, len(bookmarkEnds))
+
+        # The outer bookmark should cover the inner one.
+        # This was 'aaa bbb', not 'bbb': the bookmark start was incorrect.
+        self.assertEqual('bbb', 
bookmarkEnds[0].findall('transformed')[0].attrib['value'])
+        self.assertEqual('aaa bbb ccc', 
bookmarkEnds[1].findall('transformed')[0].attrib['value'])
+
     def test_zoom(self):
         self.dump('zoom')
         dopBase = 
self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbDop/dop/dop2007/dop2003/dop2002/dop2000/dop97/dop95/dopBase')[0]
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to