plone / plone.protect

HTTP protection utilities for the Plone CMS
https://pypi.org/project/plone.protect/
7 stars 8 forks source link

Make sure transforms don't fail on redirects #30

Closed lukasgraf closed 9 years ago

lukasgraf commented 9 years ago

The handling for redirects introduced in @6348b574 leads to this traceback when a redirect is encountered:

2015-11-02 11:58:49 ERROR plone.transformchain Unexpected error whilst trying to apply transform chain
Traceback (most recent call last):
  File "/Users/lukasgraf/Plone/eggs/plone.transformchain-1.0.4-py2.7.egg/plone/transformchain/transformer.py", line 48, in __call__
    newResult = handler.transformIterable(result, encoding)
  File "/Users/lukasgraf/Plone/buildouts/plone/plone4/src/plone.protect/plone/protect/auto.py", line 163, in transformIterable
    return self.transform(result, encoding)
  File "/Users/lukasgraf/Plone/buildouts/plone/plone4/src/plone.protect/plone/protect/auto.py", line 267, in transform
    root = result.tree.getroot()
AttributeError: 'list' object has no attribute 'tree'

This is because ProtectTransform.parseTree() returns result unchanged, which may be a list or a string.

But ProtectTransform.transform() expects it to be either None or an XMLSerializer object.

Returning None instead from parseTree() for redirects would be the proper thing to do IMHO. This should cause transform() to also return None, indicating that no transformation should be done.

Tested on Plone 4.3.7 + plone4.csrffixes.

@gforcada @vangheem

gforcada commented 9 years ago

@lukasgraf thanks for the fix, it's weird though that I never actually saw this traceback...