Skip to content

Commit

Permalink
Remove trailing and leading whitespaces from id and title on rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Mar 12, 2014
1 parent a5dfbbc commit 003f01a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Expand Up @@ -11,8 +11,8 @@
from Products.CMFPlone import PloneMessageFactory as _

paths = [path for path in paths if path]
new_ids = [id for id in new_ids if id]
new_titles = [title for title in new_titles]
new_ids = [id.strip() for id in new_ids if id]
new_titles = [title.strip() for title in new_titles]
portal = context.portal_url.getPortalObject()
check_id = context.check_id

Expand Down Expand Up @@ -44,12 +44,6 @@ for x in range(0, len(new_ids)):
if error:
state.setError(id, error)

for i in new_ids:
if i != i.strip():
context.plone_utils.addPortalMessage(
_(u'The id "%s" has leading or trailing spaces.' % i), 'error')
return state.set(status='failure')

if state.getErrors():
context.plone_utils.addPortalMessage(
_(u'Please correct the indicated errors.'), 'error')
Expand Down
3 changes: 3 additions & 0 deletions Products/CMFPlone/skins/plone_scripts/folder_rename.cpy
Expand Up @@ -17,6 +17,9 @@ request = context.REQUEST
message = None
putils = context.plone_utils

new_ids = [i.strip() for i in new_ids]
new_titles = [i.strip() for i in new_titles]

orig_template = request.get('orig_template', None)
change_template = paths and orig_template is not None
if change_template:
Expand Down
12 changes: 12 additions & 0 deletions Products/CMFPlone/tests/testFolderButtons.py
Expand Up @@ -58,6 +58,18 @@ def testTitleAndIdAreUpdatedOnFolderRename(self):
self.assertTrue(getattr(self.folder.foo, 'baz', None) is not None)
self.assertEqual(self.folder.foo.baz.Title(), title)

def testWhitespacesAreStrippedOnFolderRename(self):
# Make sure renaming removes leading and trailing whitespaces
new_title = ' Test Folder - Snooze! '
new_id = ' baz '
transaction.savepoint(optimistic=True) # make rename work
doc_path = '/'.join(self.folder.foo.doc1.getPhysicalPath())
self.folder.folder_rename(paths=[doc_path], new_ids=[new_id],
new_titles=[new_title])
self.assertEqual(getattr(self.folder.foo, 'doc1', None), None)
self.assertNotEqual(getattr(self.folder.foo, 'baz', None), None)
self.assertEqual(self.folder.foo.baz.Title(), 'Test Folder - Snooze!')

def testCatalogTitleAndIdAreUpdatedOnFolderRename(self):
# Make sure catalog updates title on rename
title = 'Test Folder - Snooze!'
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGES.rst
Expand Up @@ -11,7 +11,7 @@ Changelog
- Fix for https://dev.plone.org/ticket/13603 would break with VHM.
[spereverde, jakke, jfroche]

- Don't rename content when the new id has leading or trailing spaces.
- Strip leading & trailing spaces from id and title in rename-form.
See https://dev.plone.org/ticket/12998, https://dev.plone.org/ticket/12989,
https://dev.plone.org/ticket/9370, https://dev.plone.org/ticket/8338
[pbauer]
Expand Down

1 comment on commit 003f01a

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.roboto url : http://jenkins.plone.org/roboto/get_info?push=915e52d79e4f4ce2b37bcb31b82d7430
plone-4.3-python-2.6 [FAILURE]
plone-4.3-python-2.7 [FAILURE]

Please sign in to comment.