From 984d77a666f94bad8ebdc39b44d9e8de19a11f55 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 1 Jan 2019 09:08:44 -0800 Subject: [PATCH] output: Fix XML parsing in output_get_text_from_markup(). The XML parser requires the entire input to be enclosed in an element. --- src/output/driver.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/output/driver.c b/src/output/driver.c index c9c54ca0e6..8b5a66249d 100644 --- a/src/output/driver.c +++ b/src/output/driver.c @@ -548,18 +548,21 @@ output_driver_parse_option (const char *option, struct string_map *options) char * output_get_text_from_markup (const char *markup) { - xmlDoc *doc = xmlReadMemory (markup, strlen (markup), "noname.xml", "UTF-8", - (XML_PARSE_NOERROR | XML_PARSE_NOWARNING - | XML_PARSE_NONET | XML_PARSE_NOCDATA)); - if (!doc) + xmlParserCtxt *parser = xmlCreatePushParserCtxt (NULL, NULL, NULL, 0, NULL); + if (!parser) return xstrdup (markup); - char *content = CHAR_CAST (char *, - xmlNodeGetContent (xmlDocGetRootElement (doc))); - if (!content) - content = xstrdup (markup); - - xmlFreeDoc (doc); + xmlParseChunk (parser, "", strlen (""), false); + xmlParseChunk (parser, markup, strlen (markup), false); + xmlParseChunk (parser, "", strlen (""), true); + + char *content + = (parser->wellFormed + ? CHAR_CAST (char *, + xmlNodeGetContent (xmlDocGetRootElement (parser->myDoc))) + : xstrdup (markup)); + xmlFreeDoc (parser->myDoc); + xmlFreeParserCtxt (parser); return content; } -- 2.30.2