23 lines
1013 B
Python
23 lines
1013 B
Python
import tempfile
|
|
from pathlib import Path
|
|
from zipfile import ZipFile
|
|
from django.test import SimpleTestCase
|
|
from .word_preview import render_word_preview
|
|
|
|
|
|
class WordPreviewTests(SimpleTestCase):
|
|
def test_docx_text_escaped_and_tables(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / 'note.docx'
|
|
document = b'''<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
<w:body><w:p><w:r><w:t><script>alert(1)</script></w:t></w:r></w:p>
|
|
<w:tbl><w:tr><w:tc><w:p><w:r><w:t>Tableau</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
|
|
</w:body></w:document>'''
|
|
with ZipFile(path, 'w') as archive:
|
|
archive.writestr('word/document.xml', document)
|
|
html = render_word_preview(path)
|
|
self.assertIn('<script>', html)
|
|
self.assertNotIn('<script>', html)
|
|
self.assertIn('<table>', html)
|
|
self.assertIn('Tableau', html)
|