While looking into this report
http://www.postgresql.org/message-id/cf48ccfb.65a9d%[email protected] I
noticed that we don't accept empty values as xml "content" values, even
though this should apparently be allowed by the spec. Attached is a
patch to fix it (which needs updates to xml_1.out, which I omit here for
simplicity).
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 422be69..7abe215 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -1400,6 +1400,8 @@ static void SPI_sql_row_to_xmlelement(int rownum, StringInfo result,
doc->encoding = xmlStrdup((const xmlChar *) "UTF-8");
doc->standalone = standalone;
+ if (*(utf8string + count))
+ {
res_code = xmlParseBalancedChunkMemory(doc, NULL, NULL, 0,
utf8string + count, NULL);
if (res_code != 0 || xmlerrcxt->err_occurred)
@@ -1407,6 +1409,7 @@ static void SPI_sql_row_to_xmlelement(int rownum, StringInfo result,
"invalid XML content");
}
}
+ }
PG_CATCH();
{
if (doc != NULL)
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out
index 382f9df..6e6c673 100644
--- a/src/test/regress/expected/xml.out
+++ b/src/test/regress/expected/xml.out
@@ -194,6 +194,18 @@ SELECT xmlelement(name foo, xmlattributes('<>&"''' as funny, xml 'b<a/>r' as fun
<foo funny="<>&"'" funnier="b<a/>r"/>
(1 row)
+SELECT xmlparse(content '');
+ xmlparse
+----------
+
+(1 row)
+
+SELECT xmlparse(content ' ');
+ xmlparse
+----------
+
+(1 row)
+
SELECT xmlparse(content 'abc');
xmlparse
----------
@@ -251,6 +263,22 @@ SELECT xmlparse(content '<nosuchprefix:tag/>');
<nosuchprefix:tag/>
(1 row)
+SELECT xmlparse(document '');
+ERROR: invalid XML document
+DETAIL: line 1: switching encoding : no input
+
+^
+line 1: Document is empty
+
+^
+line 1: Start tag expected, '<' not found
+
+^
+SELECT xmlparse(document ' ');
+ERROR: invalid XML document
+DETAIL: line 1: Start tag expected, '<' not found
+
+ ^
SELECT xmlparse(document 'abc');
ERROR: invalid XML document
DETAIL: line 1: Start tag expected, '<' not found
diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql
index 90d4d67..922ab7a 100644
--- a/src/test/regress/sql/xml.sql
+++ b/src/test/regress/sql/xml.sql
@@ -60,6 +60,8 @@ CREATE TABLE xmltest (
SELECT xmlelement(name foo, xmlattributes('<>&"''' as funny, xml 'b<a/>r' as funnier));
+SELECT xmlparse(content '');
+SELECT xmlparse(content ' ');
SELECT xmlparse(content 'abc');
SELECT xmlparse(content '<abc>x</abc>');
SELECT xmlparse(content '<invalidentity>&</invalidentity>');
@@ -69,6 +71,8 @@ CREATE TABLE xmltest (
SELECT xmlparse(content '<twoerrors>&idontexist;</unbalanced>');
SELECT xmlparse(content '<nosuchprefix:tag/>');
+SELECT xmlparse(document '');
+SELECT xmlparse(document ' ');
SELECT xmlparse(document 'abc');
SELECT xmlparse(document '<abc>x</abc>');
SELECT xmlparse(document '<invalidentity>&</abc>');
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers