Skip site navigation (1) Skip section navigation (2)

Re: BUG #4822: xmlattributes encodes '&' twice

From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Cc: pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #4822: xmlattributes encodes '&' twice
Date: 2009-05-28 10:31:16
Message-ID: 20090528192528.87F7.52131E4D@oss.ntt.co.jp (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> > =# SELECT xmlelement(name a, xmlattributes('./qa?a=1&b=2' as href), 'Q&A');
> >                  xmlelement
> > --------------------------------------------
> >  <a href="./qa?a=1&amp;amp;b=2">Q&amp;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="&lt;&gt;&amp;&quot;'">content&lt;&gt;&amp;"'</element>
(1 row)


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


Attachment: not-encode-xmlattributes.patch
Description: application/octet-stream (6.6 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Heikki LinnakangasDate: 2009-05-28 11:04:25
Subject: Re: Clean shutdown and warm standby
Previous:From: Albe LaurenzDate: 2009-05-28 09:29:08
Subject: Re: User-facing aspects of serializable transactions

pgsql-bugs by date

Next:From: Peter KoczanDate: 2009-05-28 18:19:37
Subject: Re: BUG #4824: KRB5/GSSAPI authentication fails when user != principal
Previous:From: Craig RingerDate: 2009-05-28 08:19:32
Subject: Re: BUG #4825: Before installation the server not running

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group