diff options
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/element.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_soup.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/bs4/element.py b/bs4/element.py index 09a81d9..4d9c150 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -83,9 +83,9 @@ class NamespacedAttribute(unicode): # per https://www.w3.org/TR/xml-names/#defaulting name = None - if name is None: + if not name: obj = unicode.__new__(cls, prefix) - elif prefix is None: + elif not prefix: # Not really namespaced. obj = unicode.__new__(cls, name) else: diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 857eb41..f21edfa 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -688,9 +688,19 @@ class TestNamedspacedAttribute(SoupTest): a = NamespacedAttribute("xmlns", None) self.assertEqual(a, "xmlns") + a = NamespacedAttribute("xmlns", "") + self.assertEqual(a, "xmlns") + a = NamespacedAttribute("xmlns") self.assertEqual(a, "xmlns") + def test_namespace_may_be_none_or_missing(self): + a = NamespacedAttribute(None, "tag") + self.assertEqual(a, "tag") + + a = NamespacedAttribute("", "tag") + self.assertEqual(a, "tag") + def test_attribute_is_equivalent_to_colon_separated_string(self): a = NamespacedAttribute("a", "b") self.assertEqual("a:b", a) |