Re: BUG #4822: xmlattributes encodes '&' twice - Mailing list pgsql-bugs

From Itagaki Takahiro
Subject Re: BUG #4822: xmlattributes encodes '&' twice
Date
Msg-id 20090528192528.87F7.52131E4D@oss.ntt.co.jp
Whole thread Raw
In response to Re: BUG #4822: xmlattributes encodes '&' twice  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] BUG #4822: xmlattributes encodes '&' twice  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [HACKERS] BUG #4822: xmlattributes encodes '&' twice  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-bugs
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> > =# SELECT xmlelement(name a, xmlattributes('./qa?a=1&b=2' as href), 'Q&A');
> >                  xmlelement
> > --------------------------------------------
> >  <a href="./qa?a=1&amp;b=2">Q&A</a>
>
> > '&' in xmlattributes seems to be encoded twice.
>
> This was apparently broken by Peter's patch here:
> http://archives.postgresql.org/pgsql-committers/2009-04/msg00124.php
>
> We might have to add a bool flag
> to map_sql_value_to_xml_value() to enable or disable mapping of special
> characters.

Here is a patch to fix the bug. I added a parameter 'encode' to
map_sql_value_to_xml_value() and pass false for xml attributes.

    char *
    map_sql_value_to_xml_value(Datum value, Oid type, bool encode)

Also a special regression test is added for it:

SELECT xmlelement(name element,
                  xmlattributes (1 as one, 'deuce' as two, '<>&"''' as three),
                  'content', '<>&"''');
                                         xmlelement
--------------------------------------------------------------------------------------------
 <element one="1" two="deuce" three="<>&"'">content<>&"'</element>
(1 row)


Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


Attachment

pgsql-bugs by date:

Previous
From: Craig Ringer
Date:
Subject: Re: BUG #4825: Before installation the server not running
Next
From: Peter Koczan
Date:
Subject: Re: BUG #4824: KRB5/GSSAPI authentication fails when user != principal