On 2024-07-06 16:25 +0200, Tom Lane wrote: > Erik Wienhold <e...@ewie.name> writes: > > So, there must be breaking changes in 2.13.0: > > https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.13.0 > > Yeah, apparently --- I get what look like the same diffs with > libxml2 2.13.0 recently supplied by MacPorts. Grumble. > Somebody's going to have to look into that.
Here's a patch that fixes just the xmlserialize and namespace errors. Use xmlAddChildList instead of xmlAddChild for xmlserialize. That also works with 2.12.7, but I don't know about older libxml2 versions. Maybe add a version check to be safe: #if LIBXML_VERSION >= 21300 xmlAddChildList(root, content_nodes); #else xmlAddChild(root, content_nodes); #endif I don't know if using xmlAddChild in this context was ever correct. The namespace errors are tricky because xmlParseBalancedChunkMemory now returns res_code != 0 for invalid or unknown namespaces (probably other errors as well). So I just added an additional check to ignore those errors for >=2.13. But that's rather hackish. I don't know how to handle it in xml_errorHandler where those error codes are already dealt with in order to compensate for differences in error reporting across different libxml2 versions. Looks like xmlerrcxt is ignored by xmlParseBalancedChunkMemory. No idea how to deal with the remaining errors for invalid and undefined entities which appear to include less details now. That seems to be expected, judging from the release notes: > A few error messages were improved and consolidated. Please update > downstream test suites accordingly. How to deal with that in a manner that still works for pre-2.13, other than filtering out those details that are no longer included in 2.13? Or just \set VERBOSITY terse for those few test cases? But that omits the entire error detail. -- Erik
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 3e4ca874d8..9eddafde01 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -757,7 +757,7 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent) /* This attaches root to doc, so we need not free it separately. */ xmlDocSetRootElement(doc, root); - xmlAddChild(root, content_nodes); + xmlAddChildList(root, content_nodes); /* * We use this node to insert newlines in the dump. Note: in at @@ -1842,10 +1842,24 @@ xml_parse(text *data, XmlOptionType xmloption_arg, parsed_nodes); if (res_code != 0 || xmlerrcxt->err_occurred) { - xml_errsave(escontext, xmlerrcxt, - ERRCODE_INVALID_XML_CONTENT, - "invalid XML content"); - goto fail; +#if LIBXML_VERSION >= 21300 + /* + * libxml2 2.13 reports namespace errors at this point via + * res_code instead of xmlerrcxt. Ignore them here so that + * we can report the same error message as for libxml2 + * releases prior to 2.13. + */ + if (res_code != XML_NS_ERR_UNDEFINED_NAMESPACE && + res_code != XML_WAR_NS_URI) + { +#endif + xml_errsave(escontext, xmlerrcxt, + ERRCODE_INVALID_XML_CONTENT, + "invalid XML content"); + goto fail; +#if LIBXML_VERSION >= 21300 + } +#endif } } }