From fae96d430f00d23e407ce88bf1790a90081a01cf Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 16 Jul 2020 19:14:41 +0000 Subject: [PATCH] Fixed an issue where XML parser errors could be reported on '' instead of the actual input file. - Legacy-Id: 3723 --- cli/xml2rfc/parser.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cli/xml2rfc/parser.py b/cli/xml2rfc/parser.py index 9a42e6e2c..07c0c2ad8 100644 --- a/cli/xml2rfc/parser.py +++ b/cli/xml2rfc/parser.py @@ -25,7 +25,7 @@ from urlparse import urlparse, urljoin, urlsplit try: - import debug + from xml2rfc import debug assert debug except ImportError: pass @@ -199,8 +199,12 @@ def getReferenceRequest(self, request, include=False, line_no=0): original = request # Used for the error message only result = None # Our proper path if request.endswith('.dtd') or request.endswith('.ent'): - if os.path.isabs(request) or urlparse(request).netloc: - # Absolute request, return as-is + if os.path.isabs(request) and os.path.exists(request): + # Absolute request, return as-is if it exists + attempts.append(request) + result = request + elif urlparse(request).netloc: + # Network request, return as-is attempts.append(request) result = request else: @@ -319,9 +323,9 @@ def getReferenceRequest(self, request, include=False, line_no=0): # Verify the result -- either raise exception or return it if not result or (not os.path.exists(result) and not urlparse(original).netloc): if os.path.isabs(original): - xml2rfc.log.warn('A reference was requested with an absolute path, but not found ' - 'in that location. Removing the path component will cause xml2rfc to look for' - 'the file automatically in standard locations.') + xml2rfc.log.warn('A reference was requested with an absolute path: "%s", but not found ' + 'in that location. Removing the path component will cause xml2rfc to look for ' + 'the file automatically in standard locations.' % original) # Couldn't resolve. Throw an exception error = XmlRfcError('Unable to resolve external request: ' + '"' + original + '"', line_no=line_no, filename=self.source) @@ -477,7 +481,7 @@ def __init__(self, source, verbose=None, quiet=None, options=base.default_option if not library_dirs: library_dirs = os.environ.get('XML_LIBRARY', '/usr/share/xml2rfc') self.library_dirs = [] - srcdir = os.path.abspath(os.path.dirname(self.source)) + srcdir = os.path.abspath(os.path.dirname(self.source)) if source else '' for raw_dir in re.split(':|;', library_dirs) + [ srcdir ]: # Convert empty directory to source dir if raw_dir == '': @@ -517,6 +521,7 @@ def parse(self, remove_comments=True, remove_pis=False, quiet=False, strip_cdata # Get an iterating parser object file = six.BytesIO(text) + file.name = self.source context = lxml.etree.iterparse(file, dtd_validation=False, load_dtd=True, @@ -594,6 +599,7 @@ def parse(self, remove_comments=True, remove_pis=False, quiet=False, strip_cdata # Parse the XML file into a tree and create an rfc instance file = six.BytesIO(text) + file.name = self.source tree = lxml.etree.parse(file, parser) xmlrfc = XmlRfc(tree, self.default_dtd_path, nsmap=self.nsmap) xmlrfc.source = self.source