Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 795ad56

Browse files
committed
Don't get fooled by an empty prefix with a valid namespaceURI -- in
this case, the code used to generate invalid tags and attribute names with a leading colon, e.g. <:tag> or <tag :attr="foo">.
1 parent 1b26b6a commit 795ad56

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Lib/xml/dom/pulldom.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def startElementNS(self, name, tagName , attrs):
5656
# provide us with the original name. If not, create
5757
# *a* valid tagName from the current context.
5858
if tagName is None:
59-
tagName = self._current_context[uri] + ":" + localname
59+
prefix = self._current_context[uri]
60+
if prefix:
61+
tagName = prefix + ":" + localname
62+
else:
63+
tagName = localname
6064
node = self.document.createElementNS(uri, tagName)
6165
else:
6266
# When the tagname is not prefixed, it just appears as
@@ -66,7 +70,11 @@ def startElementNS(self, name, tagName , attrs):
6670
for aname,value in attrs.items():
6771
a_uri, a_localname = aname
6872
if a_uri:
69-
qname = self._current_context[a_uri] + ":" + a_localname
73+
prefix = self._current_context[a_uri]
74+
if prefix:
75+
qname = prefix + ":" + a_localname
76+
else:
77+
qname = a_localname
7078
attr = self.document.createAttributeNS(a_uri, qname)
7179
else:
7280
attr = self.document.createAttribute(a_localname)

0 commit comments

Comments
 (0)