Skip to content

Commit

Permalink
Try to sanitize strings before logging here. Twiggy freaks out in som…
Browse files Browse the repository at this point in the history
…e cases.
  • Loading branch information
ralphbean committed Apr 8, 2014
1 parent 383b55c commit 883b3ab
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def get_normalized_annotation(annotation):
)


def sanitize(string):
""" Sanitize a string for logging with twiggy.
It is obnoxious that we have to do this ourselves, but twiggy doesn't like
strings with non-ascii characters or with curly braces in them.
"""
if not isinstance(string, six.string_types):
return string
return six.text_type(string.replace('{', '{{').replace('}', '}}'))


def tasks_differ(left, right):
if set(left) - set(right):
return True
Expand All @@ -96,14 +107,14 @@ def tasks_differ(left, right):
if set(left.get(k, [])) != set(right.get(k, [])):
return True
else:
if unicode(left.get(k)) != unicode(right.get(k)):
if six.text_type(left.get(k)) != six.text_type(right.get(k)):
log.name('db').debug(
"%s:%s has changed from '%s' to '%s'." % (
left['uuid'],
k,
left.get(k),
right.get(k)
)
(u"%s:%s has changed from '%s' to '%s'." % (
sanitize(left['uuid']),
sanitize(k),
sanitize(left.get(k)),
sanitize(right.get(k))
)).encode('utf-8')
)
return True
return False
Expand Down

0 comments on commit 883b3ab

Please sign in to comment.