Commit 8c562ebb authored by Jérome Perrin's avatar Jérome Perrin

core: fix TextDocument.getData with empty text content

parent d6ce75af
...@@ -252,6 +252,7 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -252,6 +252,7 @@ class TestERP5Web(ERP5TypeTestCase):
page.edit(text_content='<b>OK</b>') page.edit(text_content='<b>OK</b>')
self.assertEqual('text/html', page.getContentType()) self.assertEqual('text/html', page.getContentType())
self.assertEqual('<b>OK</b>', page.getTextContent()) self.assertEqual('<b>OK</b>', page.getTextContent())
self.assertEqual(b'<b>OK</b>', page.getData())
def test_WebPageAsTextUTF8(self): def test_WebPageAsTextUTF8(self):
"""Check if Web Page's asText() returns utf-8 string correctly """Check if Web Page's asText() returns utf-8 string correctly
...@@ -270,6 +271,16 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -270,6 +271,16 @@ class TestERP5Web(ERP5TypeTestCase):
self.tic() self.tic()
self.assertEqual('Hé!', page.asText().strip()) self.assertEqual('Hé!', page.asText().strip())
def test_WebPageAsTextEmpty(self):
page = self.web_page_module.newContent(portal_type='Web Page')
self.tic()
self.assertIsNone(page.getTextContent())
self.assertIsNone(page.getData())
default = []
self.assertIs(page.getData(default), default)
self.assertEqual(page.asText(), '')
self.assertEqual(page.getSearchableText(), '')
def test_WebPageAsTextWrap(self): def test_WebPageAsTextWrap(self):
"""Check if Web Page's asText() is wrapped by certain column width. """Check if Web Page's asText() is wrapped by certain column width.
""" """
......
...@@ -417,7 +417,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -417,7 +417,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
return self._setContentType(value) return self._setContentType(value)
def getData(self, default=_MARKER): def getData(self, default=_MARKER):
# type: () -> bytes | PData # type: (bytes) -> bytes | PData
"""getData must returns original content but TextDocument accepts """getData must returns original content but TextDocument accepts
data or text_content to store original content. data or text_content to store original content.
Fallback on text_content property if data is not defined Fallback on text_content property if data is not defined
...@@ -427,7 +427,9 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -427,7 +427,9 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
data = self._baseGetTextContent() data = self._baseGetTextContent()
else: else:
data = self._baseGetTextContent(default) data = self._baseGetTextContent(default)
return str2bytes(data) if data is default:
return default
return str2bytes(data) if data is not None else None
else: else:
if default is _MARKER: if default is _MARKER:
return File.getData(self) return File.getData(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment