Skip to content

Commit

Permalink
Fix sanitizer error when values are None (ie nothing to sanitize at a…
Browse files Browse the repository at this point in the history
…ll).
  • Loading branch information
Andreas Kaiser committed Mar 16, 2021
1 parent acdbe1a commit dc86123
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Change History
==============

- Fix sanitizer error when values are None (ie nothing to sanitize at all).

2.0.4 - 2020-11-20
------------------

Expand Down
2 changes: 2 additions & 0 deletions kotti/sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def _setup_listeners(settings):
def _create_handler(attributename, sanitizers):
def handler(event):
value = getattr(event.object, attributename)
if value is None:
return
for sanitizer_name in sanitizers.split(","):
value = settings["kotti.sanitizers"][sanitizer_name](value)
setattr(event.object, attributename, value)
Expand Down
7 changes: 7 additions & 0 deletions kotti/tests/test_sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def test_listeners(app, root, db_session):
_verify_no_html(doc.description)
_verify_xss_protection(doc.body)

# Test None title
root["e"] = doc = Document(
name="test", title=None, description=unsanitized, body=unsanitized
)
db_session.flush()
assert doc.title == None


def test_sanitize(app, dummy_request):

Expand Down

0 comments on commit dc86123

Please sign in to comment.