Don't request pretty-printed output from xmlNodeDump().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Apr 2019 14:51:07 +0000 (10:51 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Apr 2019 14:51:07 +0000 (10:51 -0400)
xml.c passed format = 1 to xmlNodeDump(), resulting in sometimes getting
extra whitespace (newlines + spaces) in the output.  We don't really want
that, first because whitespace might be semantically significant in some
XML uses, and second because it happens only very inconsistently.  Only
one case in our regression tests is affected.

This potentially affects the results of xpath() and the XMLTABLE construct,
when emitting nodeset values.

Note that the older code in contrib/xml2 doesn't do this; it seems
to have been an aboriginal bad decision in commit ea3b212fe.

While this definitely seems like a bug to me, the small number of
complaints to date argues against back-patching a behavioral change.
Hence, fix in HEAD only, at least for now.

Per report from Jean-Marc Voillequin.

Discussion: https://postgr.es/m/1EC8157EB499BF459A516ADCF135ADCE3A23A9CA@LON-WGMSX712.ad.moodys.net

src/backend/utils/adt/xml.c
src/test/regress/expected/xml.out
src/test/regress/expected/xml_2.out

index dae7d5883b54e3c5d7a7e03cb2107c4ccb7c5412..48b8034f8d08ec880bf668c5ea47a8d31e61d6a6 100644 (file)
@@ -3857,7 +3857,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur, PgXmlErrorContext *xmlerrcxt)
            nodefree = (cur_copy->type == XML_DOCUMENT_NODE) ?
                (void (*) (xmlNodePtr)) xmlFreeDoc : xmlFreeNode;
 
-           bytes = xmlNodeDump(buf, NULL, cur_copy, 0, 1);
+           bytes = xmlNodeDump(buf, NULL, cur_copy, 0, 0);
            if (bytes == -1 || xmlerrcxt->err_occurred)
                xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY,
                            "could not dump node");
index 0aae60016bc6b983803ec44e2f6558b957e6973d..11e7d7faf3765a2f8d31353456ac47e1f1958583 100644 (file)
@@ -654,12 +654,9 @@ SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1"><local:p
 (1 row)
 
 SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1" xmlns="http://127.0.0.2"><local:piece id="1"><internal>number one</internal><internal2/></local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
-                                        xpath                                         
---------------------------------------------------------------------------------------
- {"<local:piece xmlns:local=\"http://127.0.0.1\" xmlns=\"http://127.0.0.2\" id=\"1\">+
-   <internal>number one</internal>                                                   +
-   <internal2/>                                                                      +
- </local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
+                                                                                                   xpath                                                                                                    
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"<local:piece xmlns:local=\"http://127.0.0.1\" xmlns=\"http://127.0.0.2\" id=\"1\"><internal>number one</internal><internal2/></local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
 (1 row)
 
 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
index 9756b6e88652e8e145676e81c98c9ff1f7ffcb2b..4d200274691b500f0973e6a4fcb6751a274784a2 100644 (file)
@@ -634,12 +634,9 @@ SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1"><local:p
 (1 row)
 
 SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1" xmlns="http://127.0.0.2"><local:piece id="1"><internal>number one</internal><internal2/></local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
-                                        xpath                                         
---------------------------------------------------------------------------------------
- {"<local:piece xmlns:local=\"http://127.0.0.1\" xmlns=\"http://127.0.0.2\" id=\"1\">+
-   <internal>number one</internal>                                                   +
-   <internal2/>                                                                      +
- </local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
+                                                                                                   xpath                                                                                                    
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"<local:piece xmlns:local=\"http://127.0.0.1\" xmlns=\"http://127.0.0.2\" id=\"1\"><internal>number one</internal><internal2/></local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
 (1 row)
 
 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');