Commit 2241eafc authored by Christophe François's avatar Christophe François Committed by hydrargyrum
Browse files

weboob.browser.filters.standard: handle None value in CleanText filter

Json fields can be `null`. In that case, Dict returns None,  which makes
CleanText crash if it's used on the result.

Instead of handling the case each time this happens, we return the
default value (or raise an error if there is none).
parent d37d8bf3
......@@ -262,7 +262,9 @@ def __init__(self, selector=None, symbols='', replace=[], children=True, newline
@debug()
def filter(self, txt):
if isinstance(txt, int):
if txt is None:
return self.default_or_raise(FilterError('The text cannot be None'))
elif isinstance(txt, int):
txt = str(txt)
elif isinstance(txt, (tuple, list)):
txt = u' '.join([self.clean(item, children=self.children) for item in txt])
......@@ -1042,6 +1044,8 @@ def test_CleanText():
assert CleanText(normalize='NFD').filter(u'\u3053\u3099') == u'\u3053\u3099'
assert CleanText(normalize='NFD').filter(u'\u3054') == u'\u3053\u3099'
assert CleanText(normalize=False).filter(u'\u3053\u3099') == u'\u3053\u3099'
# None value
assert_raises(FilterError, CleanText().filter, None)
def assert_raises(exc_class, func, *args, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment