Skip to content

Commit

Permalink
Update libxml2 to v2.12.7
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed May 20, 2024
1 parent cbe184f commit 3c15749
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ before_install:
esac
- curl https://bitbucket.org/Swyter/bitbucket-curl-upload-to-repo-downloads/raw/default/upload-to-bitbucket.sh -O -J -L
- chmod +x ./upload-to-bitbucket.sh
- git clone --branch v2.12.5 --depth 1 https://gitlab.gnome.org/GNOME/libxml2
- git clone --branch v2.12.7 --depth 1 https://gitlab.gnome.org/GNOME/libxml2
- mkdir -p libxml2/$PLATFORM

before_cache:
Expand Down
5 changes: 4 additions & 1 deletion ExternData/Resources/C-Sources/libxml2/HTMLparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5987,7 +5987,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,

xmlInitParser();

buf = xmlAllocParserInputBuffer(enc);
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
if (buf == NULL) return(NULL);

ctxt = htmlNewSAXParserCtxt(sax, user_data);
Expand Down Expand Up @@ -6018,6 +6018,9 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,

inputPush(ctxt, inputStream);

if (enc != XML_CHAR_ENCODING_NONE)
xmlSwitchEncoding(ctxt, enc);

if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
(ctxt->input->buf != NULL)) {
size_t pos = ctxt->input->cur - ctxt->input->base;
Expand Down
12 changes: 1 addition & 11 deletions ExternData/Resources/C-Sources/libxml2/SAX2.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,17 +955,7 @@ xmlSAX2EndDocument(void *ctx)

doc = ctxt->myDoc;
if ((doc != NULL) && (doc->encoding == NULL)) {
const xmlChar *encoding = NULL;

if ((ctxt->input->flags & XML_INPUT_USES_ENC_DECL) ||
(ctxt->input->flags & XML_INPUT_AUTO_ENCODING)) {
/* Preserve encoding exactly */
encoding = ctxt->encoding;
} else if ((ctxt->input->buf) && (ctxt->input->buf->encoder)) {
encoding = BAD_CAST ctxt->input->buf->encoder->name;
} else if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
encoding = BAD_CAST "UTF-8";
}
const xmlChar *encoding = xmlGetActualEncoding(ctxt);

if (encoding != NULL) {
doc->encoding = xmlStrdup(encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ XMLPUBFUN void xmlCheckVersion(int version);
*
* the version string like "1.2.3"
*/
#define LIBXML_DOTTED_VERSION "2.12.5"
#define LIBXML_DOTTED_VERSION "2.12.7"

/**
* LIBXML_VERSION:
*
* the version number: 1.2.3 value is 10203
*/
#define LIBXML_VERSION 21205
#define LIBXML_VERSION 21207

/**
* LIBXML_VERSION_STRING:
*
* the version number string, 1.2.3 value is "10203"
*/
#define LIBXML_VERSION_STRING "21205"
#define LIBXML_VERSION_STRING "21207"

/**
* LIBXML_VERSION_EXTRA:
Expand All @@ -58,7 +58,7 @@ XMLPUBFUN void xmlCheckVersion(int version);
* Macro to check that the libxml version in use is compatible with
* the version the software has been compiled against
*/
#define LIBXML_TEST_VERSION xmlCheckVersion(21205);
#define LIBXML_TEST_VERSION xmlCheckVersion(21207);

#ifndef VMS
#if 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ XML_HIDDEN void
xmlDetectEncoding(xmlParserCtxtPtr ctxt);
XML_HIDDEN void
xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding);
XML_HIDDEN const xmlChar *
xmlGetActualEncoding(xmlParserCtxtPtr ctxt);

XML_HIDDEN xmlParserNsData *
xmlParserNsCreate(void);
Expand Down
2 changes: 1 addition & 1 deletion ExternData/Resources/C-Sources/libxml2/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -9424,7 +9424,7 @@ xmlAttrHashInsert(xmlParserCtxtPtr ctxt, unsigned size, const xmlChar *name,
int nsIndex = (int) (ptrdiff_t) atts[2];

if ((nsIndex == NS_INDEX_EMPTY) ? (uri == NULL) :
(nsIndex == NS_INDEX_XML) ? (uri == ctxt->str_xml) :
(nsIndex == NS_INDEX_XML) ? (uri == ctxt->str_xml_ns) :
(uri == ctxt->nsTab[nsIndex * 2 + 1]))
return(bucket->index);
}
Expand Down
24 changes: 24 additions & 0 deletions ExternData/Resources/C-Sources/libxml2/parserInternals.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,30 @@ xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding) {
}
}

/**
* xmlGetActualEncoding:
* @ctxt: the parser context
*
* Returns the actual used to parse the document. This can differ from
* the declared encoding.
*/
const xmlChar *
xmlGetActualEncoding(xmlParserCtxtPtr ctxt) {
const xmlChar *encoding = NULL;

if ((ctxt->input->flags & XML_INPUT_USES_ENC_DECL) ||
(ctxt->input->flags & XML_INPUT_AUTO_ENCODING)) {
/* Preserve encoding exactly */
encoding = ctxt->encoding;
} else if ((ctxt->input->buf) && (ctxt->input->buf->encoder)) {
encoding = BAD_CAST ctxt->input->buf->encoder->name;
} else if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
encoding = BAD_CAST "UTF-8";
}

return(encoding);
}

/************************************************************************
* *
* Commodity functions to handle entities processing *
Expand Down
22 changes: 10 additions & 12 deletions ExternData/Resources/C-Sources/libxml2/xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#endif

#include "private/buf.h"
#include "private/parser.h"
#include "private/tree.h"
#ifdef LIBXML_XINCLUDE_ENABLED
#include "private/xinclude.h"
Expand Down Expand Up @@ -2795,20 +2796,17 @@ xmlTextReaderReadAttributeValue(xmlTextReaderPtr reader) {
*/
const xmlChar *
xmlTextReaderConstEncoding(xmlTextReaderPtr reader) {
xmlDocPtr doc = NULL;
const xmlChar *encoding = NULL;

if (reader == NULL)
return(NULL);
if (reader->doc != NULL)
doc = reader->doc;
else if (reader->ctxt != NULL)
doc = reader->ctxt->myDoc;
if (doc == NULL)
return(NULL);
return(NULL);

if (doc->encoding == NULL)
return(NULL);
else
return(CONSTSTR(doc->encoding));
if (reader->ctxt != NULL)
encoding = xmlGetActualEncoding(reader->ctxt);
else if (reader->doc != NULL)
encoding = reader->doc->encoding;

return(CONSTSTR(encoding));
}


Expand Down
34 changes: 22 additions & 12 deletions ExternData/Resources/C-Sources/libxml2/xmlsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,13 +1391,14 @@ xhtmlAttrListDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) {
static void
xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
int format = ctxt->format, addmeta;
xmlNodePtr tmp, root, unformattedNode = NULL;
xmlNodePtr tmp, root, unformattedNode = NULL, parent;
xmlChar *start, *end;
xmlOutputBufferPtr buf = ctxt->buf;

if (cur == NULL) return;

root = cur;
parent = cur->parent;
while (1) {
switch (cur->type) {
case XML_DOCUMENT_NODE:
Expand All @@ -1414,7 +1415,9 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
break;

case XML_DOCUMENT_FRAG_NODE:
if (cur->children) {
/* Always validate cur->parent when descending. */
if ((cur->parent == parent) && (cur->children != NULL)) {
parent = cur;
cur = cur->children;
continue;
}
Expand All @@ -1441,6 +1444,16 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
ctxt->indent_nr : ctxt->level),
ctxt->indent);

/*
* Some users like lxml are known to pass nodes with a corrupted
* tree structure. Fall back to a recursive call to handle this
* case.
*/
if ((cur->parent != parent) && (cur->children != NULL)) {
xhtmlNodeDumpOutput(ctxt, cur);
break;
}

xmlOutputBufferWrite(buf, 1, "<");
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix);
Expand All @@ -1461,10 +1474,10 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
if (cur->properties != NULL)
xhtmlAttrListDumpOutput(ctxt, cur->properties);

if ((cur->parent != NULL) &&
(cur->parent->parent == (xmlNodePtr) cur->doc) &&
if ((parent != NULL) &&
(parent->parent == (xmlNodePtr) cur->doc) &&
xmlStrEqual(cur->name, BAD_CAST"head") &&
xmlStrEqual(cur->parent->name, BAD_CAST"html")) {
xmlStrEqual(parent->name, BAD_CAST"html")) {

tmp = cur->children;
while (tmp != NULL) {
Expand Down Expand Up @@ -1570,6 +1583,7 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {

if (ctxt->format == 1) xmlOutputBufferWrite(buf, 1, "\n");
if (ctxt->level >= 0) ctxt->level++;
parent = cur;
cur = cur->children;
continue;
}
Expand Down Expand Up @@ -1664,13 +1678,9 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
break;
}

/*
* The parent should never be NULL here but we want to handle
* corrupted documents gracefully.
*/
if (cur->parent == NULL)
return;
cur = cur->parent;
cur = parent;
/* cur->parent was validated when descending. */
parent = cur->parent;

if (cur->type == XML_ELEMENT_NODE) {
if (ctxt->level > 0) ctxt->level--;
Expand Down

0 comments on commit 3c15749

Please sign in to comment.