From 5da090bdd9811ee2d8e76bb536fd84dc9d556033 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 18 Jul 2016 22:29:42 +0200 Subject: [PATCH] GH#198: fix file path encoding and error handling in resolver code --- src/lxml/parser.pxi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi index 0c0a8b206..bccc79bae 100644 --- a/src/lxml/parser.pxi +++ b/src/lxml/parser.pxi @@ -445,10 +445,19 @@ cdef xmlparser.xmlParserInput* _local_resolver(const_char* c_url, const_char* c_ if doc_ref is not None: if doc_ref._type == PARSER_DATA_STRING: data = doc_ref._data_bytes + filename = doc_ref._filename + if not filename: + filename = None + elif not isinstance(filename, bytes): + # most likely a text URL + filename = filename.encode('utf8') + if not isinstance(filename, bytes): + filename = None + c_input = xmlparser.xmlNewInputStream(c_context) if c_input is not NULL: - if doc_ref._filename: - c_input.filename = tree.xmlStrdup(_xcstr(doc_ref._filename)) + if filename is not None: + c_input.filename = tree.xmlStrdup(_xcstr(filename)) c_input.base = _xcstr(data) c_input.length = python.PyBytes_GET_SIZE(data) c_input.cur = c_input.base