Skip to content

Commit cab1d2f

Browse files
michaelpqleborchuk
authored andcommitted
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. Author: Dmitry Koval Discussion: https://postgr.es/m/18274-98d16bc03520665f@postgresql.org
1 parent 287e887 commit cab1d2f

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

contrib/xml2/xpath.c

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

77-
xmlSubstituteEntitiesDefault(1);
7877

7978
return xmlerrcxt;
8079
}
@@ -424,8 +423,9 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
424423

425424
PG_TRY();
426425
{
427-
workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
428-
docsize);
426+
workspace->doctree = xmlReadMemory((char *) VARDATA_ANY(document),
427+
docsize, NULL, NULL,
428+
XML_PARSE_NOENT);
429429
if (workspace->doctree != NULL)
430430
{
431431
workspace->ctxt = xmlXPathNewContext(workspace->doctree);
@@ -718,7 +718,9 @@ xpath_table(PG_FUNCTION_ARGS)
718718

719719
/* Parse the document */
720720
if (xmldoc)
721-
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
721+
doctree = xmlReadMemory(xmldoc, strlen(xmldoc),
722+
NULL, NULL,
723+
XML_PARSE_NOENT);
722724
else /* treat NULL as not well-formed */
723725
doctree = NULL;
724726

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)