Skip to content

Commit

Permalink
Work around libxml2 bug in affected versions that failed to reset the…
Browse files Browse the repository at this point in the history
… namespace count in the parser context.

See https://gitlab.gnome.org/GNOME/libxml2/-/issues/378
  • Loading branch information
scoder committed Jul 19, 2022
1 parent 56de38e commit c742576
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lxml/includes/xmlparser.pxd
Expand Up @@ -144,6 +144,7 @@ cdef extern from "libxml/parser.h":
void* userData
int* spaceTab
int spaceMax
int nsNr
bint html
bint progressive
int inSubset
Expand Down
3 changes: 3 additions & 0 deletions src/lxml/parser.pxi
Expand Up @@ -569,6 +569,9 @@ cdef class _ParserContext(_ResolverContext):
self._c_ctxt.disableSAX = 0 # work around bug in libxml2
else:
xmlparser.xmlClearParserCtxt(self._c_ctxt)
# work around bug in libxml2 [2.9.10 .. 2.9.14]:
# https://gitlab.gnome.org/GNOME/libxml2/-/issues/378
self._c_ctxt.nsNr = 0

cdef int prepare(self, bint set_document_loader=True) except -1:
cdef int result
Expand Down
3 changes: 1 addition & 2 deletions src/lxml/tests/test_etree.py
Expand Up @@ -1491,8 +1491,7 @@ def test_walk_after_parse_failure(self):
# This would be the expected result, because there was no namespace
pass
else:
# This is a bug in libxml2
assert not ns, repr(ns)
assert False, "Found unexpected namespace '%s'" % ns

def test_itertext_comment_pi(self):
# https://bugs.launchpad.net/lxml/+bug/1844674
Expand Down

0 comments on commit c742576

Please sign in to comment.