Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/+7b7c8b72.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Restrict title to 1024 and description to 10000.
This is for images and files. For others, a similar change is done in ``plone.app.dexterity``.
[maurits]
2 changes: 2 additions & 0 deletions plone/app/contenttypes/schema/file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
type="zope.schema.TextLine"
>
<description />
<max_length>1024</max_length>
<required>False</required>
<title i18n:translate="">Title</title>
</field>
<field name="description"
type="zope.schema.Text"
>
<description />
<max_length>10000</max_length>
<required>False</required>
<title i18n:translate="">Description</title>
</field>
Expand Down
2 changes: 2 additions & 0 deletions plone/app/contenttypes/schema/image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
type="zope.schema.TextLine"
>
<description />
<max_length>1024</max_length>
<required>False</required>
<title i18n:translate="">Title</title>
</field>
<field name="description"
type="zope.schema.Text"
>
<description />
<max_length>10000</max_length>
<required>False</required>
<title i18n:translate="">Description</title>
</field>
Expand Down
9 changes: 7 additions & 2 deletions plone/app/contenttypes/subscribers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from plone.app.contenttypes.interfaces import IImage

try:
from plone.app.dexterity.config import MAX_TITLE_LENGTH as _MAX_TITLE_LENGTH
except ImportError:
_MAX_TITLE_LENGTH = 1024


def set_title_description(obj, event):
"""Sets title to filename if no title
Expand All @@ -14,8 +19,8 @@ def set_title_description(obj, event):
else:
datafield = obj.file
if datafield:
filename = datafield.filename
obj.title = filename
filename = datafield.filename or ""
obj.title = filename[:_MAX_TITLE_LENGTH]

description = obj.description
if not description:
Expand Down
42 changes: 42 additions & 0 deletions plone/app/contenttypes/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ def test_shortname_file(self):
self.browser.getControl("Save").click()
self.assertTrue(self.browser.url.endswith("my-special-file/view"))

def test_long_filename(self):
self.browser.open(self.portal_url)
self.browser.getLink("File").click()
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.file")
filename = "i" * 2000 + ".png"
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", filename)
self.browser.getControl("Save").click()
# Something, likely Zope, already restricts the id to 255 characters,
# although this does not count the ".png" suffix.
content_id = "i" * 255 + ".png"
self.assertTrue(self.browser.url.endswith(f"{content_id}/view"))
content = self.portal[content_id]
self.assertTrue(content.Title(), filename[:1024])

def test_long_title(self):
self.browser.open(self.portal_url)
self.browser.getLink("File").click()
widget = "form.widgets.description"
self.browser.getControl(name=widget).value = "L" * 10001
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.file")
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", "image.jpg")
self.browser.getControl("Save").click()
self.assertTrue("There were some errors." in self.browser.contents)
self.assertTrue("Value is too long" in self.browser.contents)

def test_long_description(self):
self.browser.open(self.portal_url)
self.browser.getLink("File").click()
widget = "form.widgets.title"
self.browser.getControl(name=widget).value = "L" * 1025
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.file")
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", "image.jpg")
self.browser.getControl("Save").click()
self.assertTrue("There were some errors." in self.browser.contents)
self.assertTrue("Value is too long" in self.browser.contents)

def test_mime_icon_pdf_for_file_(self):
self.browser.open(self.portal_url)
self.browser.getLink("File").click()
Expand Down
42 changes: 42 additions & 0 deletions plone/app/contenttypes/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,48 @@ def test_add_image_with_shortname(self):
self.browser.getControl("Save").click()
self.assertTrue(self.browser.url.endswith("my-special-image.jpg/view"))

def test_long_filename(self):
self.browser.open(self.portal_url)
self.browser.getLink("Image").click()
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.image")
filename = "i" * 2000 + ".png"
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", filename)
self.browser.getControl("Save").click()
# Something, likely Zope, already restricts the id to 255 characters,
# although this does not count the ".png" suffix.
content_id = "i" * 255 + ".png"
self.assertTrue(self.browser.url.endswith(f"{content_id}/view"))
content = self.portal[content_id]
self.assertTrue(content.Title(), filename[:1024])

def test_long_title(self):
self.browser.open(self.portal_url)
self.browser.getLink("Image").click()
widget = "form.widgets.description"
self.browser.getControl(name=widget).value = "L" * 10001
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.image")
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", "image.jpg")
self.browser.getControl("Save").click()
self.assertTrue("There were some errors." in self.browser.contents)
self.assertTrue("Value is too long" in self.browser.contents)

def test_long_description(self):
self.browser.open(self.portal_url)
self.browser.getLink("Image").click()
widget = "form.widgets.title"
self.browser.getControl(name=widget).value = "L" * 1025
file_path = os.path.join(os.path.dirname(__file__), "image.jpg")
file_ctl = self.browser.getControl(name="form.widgets.image")
with io.FileIO(file_path, "rb") as f:
file_ctl.add_file(f, "image/png", "image.jpg")
self.browser.getControl("Save").click()
self.assertTrue("There were some errors." in self.browser.contents)
self.assertTrue("Value is too long" in self.browser.contents)

def test_image_view_fullscreen(self):
self.browser.open(self.portal_url)
self.browser.getLink("Image").click()
Expand Down