Skip to content

Commit 7c93f31

Browse files
committed
xml2: Replace deprecated routines with recommended ones
Some functions are used in the tree and are currently marked as deprecated by upstream. This commit refreshes the code to use the recommended functions, leading to the following changes: - xmlSubstituteEntitiesDefault() is gone, and needs to be replaced with XML_PARSE_NOENT for the paths doing the parsing. - xmlParseMemory() -> xmlReadMemory(). These functions, as well as more functions setting global states, have been officially marked as deprecated by upstream in August 2022. Their replacements exist since the 2001-ish area, as far as I have checked, so that should be safe. This has been originally applied as 65c5864 without a backpatch, and this has come up as well when working on 400928b. Per request from Tom Lane, for new buildfarm member indri that is able to see deprecation warnings with xmlSubstituteEntitiesDefault() in 16 and older stable branches. Author: Dmitry Koval Discussion: https://postgr.es/m/18274-98d16bc03520665f@postgresql.org Discussion: https://postgr.es/m/1012981.1713222862@sss.pgh.pa.us Bakpatch-through: 12
1 parent cc1eb6a commit 7c93f31

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

contrib/xml2/xpath.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ pgxml_parser_init(PgXmlStrictness strictness)
7474
/* Initialize libxml */
7575
xmlInitParser();
7676

77-
xmlSubstituteEntitiesDefault(1);
78-
7977
return xmlerrcxt;
8078
}
8179

@@ -379,8 +377,9 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
379377

380378
PG_TRY();
381379
{
382-
workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
383-
docsize);
380+
workspace->doctree = xmlReadMemory((char *) VARDATA_ANY(document),
381+
docsize, NULL, NULL,
382+
XML_PARSE_NOENT);
384383
if (workspace->doctree != NULL)
385384
{
386385
workspace->ctxt = xmlXPathNewContext(workspace->doctree);
@@ -623,7 +622,9 @@ xpath_table(PG_FUNCTION_ARGS)
623622

624623
/* Parse the document */
625624
if (xmldoc)
626-
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
625+
doctree = xmlReadMemory(xmldoc, strlen(xmldoc),
626+
NULL, NULL,
627+
XML_PARSE_NOENT);
627628
else /* treat NULL as not well-formed */
628629
doctree = NULL;
629630

contrib/xml2/xslt_proc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ xslt_process(PG_FUNCTION_ARGS)
8585
bool xslt_sec_prefs_error;
8686

8787
/* Parse document */
88-
doctree = xmlParseMemory((char *) VARDATA_ANY(doct),
89-
VARSIZE_ANY_EXHDR(doct));
88+
doctree = xmlReadMemory((char *) VARDATA_ANY(doct),
89+
VARSIZE_ANY_EXHDR(doct), NULL, NULL,
90+
XML_PARSE_NOENT);
9091

9192
if (doctree == NULL)
9293
xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
9394
"error parsing XML document");
9495

9596
/* Same for stylesheet */
96-
ssdoc = xmlParseMemory((char *) VARDATA_ANY(ssheet),
97-
VARSIZE_ANY_EXHDR(ssheet));
97+
ssdoc = xmlReadMemory((char *) VARDATA_ANY(ssheet),
98+
VARSIZE_ANY_EXHDR(ssheet), NULL, NULL,
99+
XML_PARSE_NOENT);
98100

99101
if (ssdoc == NULL)
100102
xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,

0 commit comments

Comments
 (0)