Remove dangling references from document.xml.rels
The file `word/_rels/document.xml.rels` is similar to `[Content_Types].xml` and has references to other files in the archive. If those references aren't removed Word refuses to open the document. # Please enter the commit message for your changes. Lines starting
This commit is contained in:
parent
09672a2dcc
commit
156855ab7e
2 changed files with 58 additions and 1 deletions
|
@ -931,3 +931,24 @@ class TextDocx(unittest.TestCase):
|
|||
|
||||
os.remove('./tests/data/comment_clean.docx')
|
||||
os.remove('./tests/data/comment_clean.cleaned.docx')
|
||||
|
||||
def test_clean_document_xml_rels(self):
|
||||
with zipfile.ZipFile('./tests/data/comment.docx') as zipin:
|
||||
c = zipin.open('word/_rels/document.xml.rels')
|
||||
content = c.read()
|
||||
r = b'Target="comments.xml"'
|
||||
self.assertIn(r, content)
|
||||
|
||||
shutil.copy('./tests/data/comment.docx', './tests/data/comment_clean.docx')
|
||||
p = office.MSOfficeParser('./tests/data/comment_clean.docx')
|
||||
self.assertTrue(p.remove_all())
|
||||
|
||||
with zipfile.ZipFile('./tests/data/comment_clean.cleaned.docx') as zipin:
|
||||
c = zipin.open('word/_rels/document.xml.rels')
|
||||
content = c.read()
|
||||
r = b'Target="comments.xml"'
|
||||
self.assertNotIn(r, content)
|
||||
|
||||
os.remove('./tests/data/comment_clean.docx')
|
||||
os.remove('./tests/data/comment_clean.cleaned.docx')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue