Error log locations are zeroed out
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Triaged
|
Undecided
|
Unassigned |
Bug Description
Errors in the context error_log may have their line and column set to zero (and the path is None) when reporting on errors from a schema.
This error occurs in python but not in xmllint.
OS info:
$ uname -a
Darwin Nix.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-
Requested information:
>>> print("%-20s: %s" % ('Python', sys.version_info))
Python : sys.version_
>>> print("%-20s: %s" % ('lxml.etree', etree.LXML_
lxml.etree : (4, 2, 0, 0)
>>> print("%-20s: %s" % ('libxml used', etree.LIBXML_
libxml used : (2, 9, 8)
>>> print("%-20s: %s" % ('libxml compiled', etree.LIBXML_
libxml compiled : (2, 9, 8)
>>> print("%-20s: %s" % ('libxslt used', etree.LIBXSLT_
libxslt used : (1, 1, 32)
>>> print("%-20s: %s" % ('libxslt compiled', etree.LIBXSLT_
libxslt compiled : (1, 1, 32)
Files / code to reproduce:
test.py
--------
#!/usr/bin/env python3
from lxml.etree import parse, XMLSchema, iterparse, XMLSyntaxError
xml_file = 'test.xml'
xsd_file = 'library.xsd'
xsd_document = parse(xsd_file)
schema = XMLSchema(
context = iterparse(xml_file, schema=schema)
try:
for _, elem in context:
pass
except XMLSyntaxError as error:
for error in context.error_log:
print('At', error.line, ':', error.column,'(', error.path, ')', error.message)
library.xsd
------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:d="http://
xmlns:xs="http://
targetNamesp
<xs:element name="document">
<
</xs:element>
</xs:schema>
test.xml
---------
<?xml version="1.0"?>
<d:document xmlns:d="http://
<d:dog/>
</d:document>
Python output:
---------------
$ ./test.py
At 0 : 0 ( None ) Element '{http://
^^ Note that the line is set to 0 rather than 3
xmllint output:
----------------
$ xmllint --version
xmllint: using libxml version 20905
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
$ xmllint --noout --schema library.xsd test.xml
test.xml:3: element dog: Schemas validity error : Element '{http://
test.xml fails to validate
Probably worth investigating what xmllint does differently here. Or just put a print statement in xmlerror.pxi to see what exact error information libxml2 reports here, and if there is anything else that can be extracted from it.