mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Ensure that xpath() escapes special characters in string values.
Without this it's possible for the output to not be legal XML, as illustrated by the added regression test cases. NB: this change will need to be called out as an incompatibility in the 9.2 release notes, since it's possible somebody was relying on the old behavior, even though it's clearly wrong. Florian Pflug, reviewed by Radoslaw Smogura
This commit is contained in:
parent
17a16eeb7c
commit
aaf15e5c1c
@ -3537,7 +3537,11 @@ xml_xmlnodetoxmltype(xmlNodePtr cur)
|
|||||||
str = xmlXPathCastNodeToString(cur);
|
str = xmlXPathCastNodeToString(cur);
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
result = (xmltype *) cstring_to_text((char *) str);
|
/* Here we rely on XML having the same representation as TEXT */
|
||||||
|
char *escaped = escape_xml((char *) str);
|
||||||
|
|
||||||
|
result = (xmltype *) cstring_to_text(escaped);
|
||||||
|
pfree(escaped);
|
||||||
}
|
}
|
||||||
PG_CATCH();
|
PG_CATCH();
|
||||||
{
|
{
|
||||||
|
@ -589,6 +589,18 @@ SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
|
|||||||
{<b>two</b>,<b>etc</b>}
|
{<b>two</b>,<b>etc</b>}
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT xpath('//text()', '<root><</root>');
|
||||||
|
xpath
|
||||||
|
--------
|
||||||
|
{<}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT xpath('//@value', '<root value="<"/>');
|
||||||
|
xpath
|
||||||
|
--------
|
||||||
|
{<}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Test xmlexists and xpath_exists
|
-- Test xmlexists and xpath_exists
|
||||||
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
||||||
xmlexists
|
xmlexists
|
||||||
|
@ -504,6 +504,18 @@ LINE 1: SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>'...
|
|||||||
^
|
^
|
||||||
DETAIL: This functionality requires the server to be built with libxml support.
|
DETAIL: This functionality requires the server to be built with libxml support.
|
||||||
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
||||||
|
SELECT xpath('//text()', '<root><</root>');
|
||||||
|
ERROR: unsupported XML feature
|
||||||
|
LINE 1: SELECT xpath('//text()', '<root><</root>');
|
||||||
|
^
|
||||||
|
DETAIL: This functionality requires the server to be built with libxml support.
|
||||||
|
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
||||||
|
SELECT xpath('//@value', '<root value="<"/>');
|
||||||
|
ERROR: unsupported XML feature
|
||||||
|
LINE 1: SELECT xpath('//@value', '<root value="<"/>');
|
||||||
|
^
|
||||||
|
DETAIL: This functionality requires the server to be built with libxml support.
|
||||||
|
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
||||||
-- Test xmlexists and xpath_exists
|
-- Test xmlexists and xpath_exists
|
||||||
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
||||||
ERROR: unsupported XML feature
|
ERROR: unsupported XML feature
|
||||||
|
@ -175,6 +175,8 @@ SELECT xpath('', '<!-- error -->');
|
|||||||
SELECT xpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>');
|
SELECT xpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>');
|
||||||
SELECT xpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
|
SELECT xpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
|
||||||
SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
|
SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
|
||||||
|
SELECT xpath('//text()', '<root><</root>');
|
||||||
|
SELECT xpath('//@value', '<root value="<"/>');
|
||||||
|
|
||||||
-- Test xmlexists and xpath_exists
|
-- Test xmlexists and xpath_exists
|
||||||
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>');
|
||||||
|
Loading…
Reference in New Issue
Block a user