pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
XML element with special characters can be created, serialized, but not deserialized
2+ messages / 2 participants
[nested] [flat]

* XML element with special characters can be created, serialized, but not deserialized
@ 2023-05-16 10:02  Sergiu Ignat <sergiu@bitsoftware.ro>
  0 siblings, 1 reply; 2+ messages in thread

From: Sergiu Ignat @ 2023-05-16 10:02 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

Hello,

I am using PostgreSQL 13.8 and I think that I found an issue with XML
serialization and deserialization.

A text that has special characters cannot be converted to XML even if it
was created by serializing an XML element.

In our case a string contains a special character with the ASCII code 19,
placed between the letters i and p.
The simple statement that serializes an XML element works.
select xmlelement(name "street",'i p')::text

When the same text has to be converted back to XML. it fails with an error

select xmlelement(name "street",'i p')::text::xml

The error message is

SQL Error [2200N]: ERROR: invalid XML content
  Detail: line 1: PCDATA invalid Char value 19
<street>i p</street>
         ^
line 1: chunk is not well balanced
<street>i p</street>
                    ^

The expected behaviour would be to successfully parse an XML element that
was created and serialized by the same engine.

Best regards,
-- 
Serghei Ignat

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: XML element with special characters can be created, serialized, but not deserialized
@ 2023-05-16 15:21  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sergiu Ignat <sergiu@bitsoftware.ro>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-05-16 15:21 UTC (permalink / raw)
  To: Sergiu Ignat <sergiu@bitsoftware.ro>; +Cc: pgsql-bugs@lists.postgresql.org

Sergiu Ignat <sergiu@bitsoftware.ro> writes:
> I am using PostgreSQL 13.8 and I think that I found an issue with XML
> serialization and deserialization.

Hmm.  The root cause here seems to be that escape_xml() thinks it
doesn't need to escape ASCII control characters, other than CR (\r).
Which is a bit backwards, because after some googling I conclude that
XML 1.1 requires all C0 and C1 control characters to be represented as
numeric escapes *except* CR, LF, and TAB [1].

What we probably ought to do is escape all except LF and TAB.
However, I'm a bit hesitant to back-patch such a behavioral change.
Maybe change this in HEAD (v16) only?

			regards, tom lane

[1] https://www.w3.org/International/questions/qa-controls





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-05-16 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 10:02 XML element with special characters can be created, serialized, but not deserialized Sergiu Ignat <sergiu@bitsoftware.ro>
2023-05-16 15:21 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox