Skip to content

Commit 65c5864

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. Author: Dmitry Koval Discussion: https://postgr.es/m/18274-98d16bc03520665f@postgresql.org
1 parent 8ad1f7d commit 65c5864

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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
xmlLoadExtDtdDefaultValue = 1;
7978

8079
return xmlerrcxt;
@@ -380,8 +379,9 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
380379

381380
PG_TRY();
382381
{
383-
workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
384-
docsize);
382+
workspace->doctree = xmlReadMemory((char *) VARDATA_ANY(document),
383+
docsize, NULL, NULL,
384+
XML_PARSE_NOENT);
385385
if (workspace->doctree != NULL)
386386
{
387387
workspace->ctxt = xmlXPathNewContext(workspace->doctree);
@@ -624,7 +624,9 @@ xpath_table(PG_FUNCTION_ARGS)
624624

625625
/* Parse the document */
626626
if (xmldoc)
627-
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
627+
doctree = xmlReadMemory(xmldoc, strlen(xmldoc),
628+
NULL, NULL,
629+
XML_PARSE_NOENT);
628630
else /* treat NULL as not well-formed */
629631
doctree = NULL;
630632

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)