summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG6
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/tests/test_soup.py10
3 files changed, 18 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 625bb34..f610bc7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+= 4.9.4 (unreleased)
+
+* Corrected output when the namespace prefix associated with a
+ namespaced attribute is the empty string, as opposed to
+ None. [bug=1915583]
+
= 4.9.3 (20201003)
* Implemented a significant performance optimization to the process of
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)