diff --git a/htmlement.py b/htmlement.py index ef0d8c2..8dfd567 100644 --- a/htmlement.py +++ b/htmlement.py @@ -330,7 +330,7 @@ def _handle_starttag(self, tag, attrs, self_closing=False): # Add tag element to tree if we have no filter or that the filter matches if enabled or self._search(tag, attrs): # Convert attrs to dictionary - attrs = dict(attrs) if attrs else {} + attrs = {k: v or "" for k, v in attrs} self._flush() # Create the new element diff --git a/tests/test_module.py b/tests/test_module.py index 0b3559e..3ae3a4f 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -129,6 +129,14 @@ def test_extra_tag(): assert Etree.tostring(root, method="html") == b'' +def test_find_empty_attribute(): + # Check whether we can find an element with an empty-valued attribute + html = "
" + form = quick_parse_filter(html, "form", {"autofocus": True}) + assert "autofocus" in form.attrib + assert form.find(".//input[@checked]") is not None + + # ############################# HTML Entity ############################## #