From 9a37828bd2d009fbe34aeb4128be6a606640775c Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 17 May 2014 21:48:32 +0100 Subject: [PATCH] Fix optionaltags filter to not error when filtering nothing. --- html5lib/filters/optionaltags.py | 3 ++- html5lib/tests/test_optionaltags_filter.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 html5lib/tests/test_optionaltags_filter.py diff --git a/html5lib/filters/optionaltags.py b/html5lib/filters/optionaltags.py index fefe0b30..88e5ff47 100644 --- a/html5lib/filters/optionaltags.py +++ b/html5lib/filters/optionaltags.py @@ -11,7 +11,8 @@ def slider(self): yield previous2, previous1, token previous2 = previous1 previous1 = token - yield previous2, previous1, None + if previous1 is not None: + yield previous2, previous1, None def __iter__(self): for previous, token, next in self.slider(): diff --git a/html5lib/tests/test_optionaltags_filter.py b/html5lib/tests/test_optionaltags_filter.py new file mode 100644 index 00000000..cd282149 --- /dev/null +++ b/html5lib/tests/test_optionaltags_filter.py @@ -0,0 +1,7 @@ +from __future__ import absolute_import, division, unicode_literals + +from html5lib.filters.optionaltags import Filter + + +def test_empty(): + assert list(Filter([])) == []