Re: xmlserialize bug - extra empty row at the end

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: xmlserialize bug - extra empty row at the end
Date: 2023-04-23 12:02:17
Message-ID: c3d5b8ba-156b-ed1e-67b3-c5934f51248a@uni-muenster.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23.04.23 07:31, Pavel Stehule wrote:
> Hi
>
> maybe I found a bug in xmlserialize
>
> SELECT xmlserialize(DOCUMENT '<foo><bar><val
> x="y">42</val></bar></foo>' AS varchar INDENT);
>
> (2023-04-23 07:27:53) postgres=# SELECT xmlserialize(DOCUMENT
> '<foo><bar><val x="y">42</val></bar></foo>' AS varchar INDENT);
> ┌─────────────────────────┐
> │      xmlserialize       │
> ╞═════════════════════════╡
> │ <foo>                  ↵│
> │   <bar>                ↵│
> │     <val x="y">42</val>↵│
> │   </bar>               ↵│
> │ </foo>                 ↵│
> │                         │
> └─────────────────────────┘
> (1 row)
>
> Looks so there is an extra empty row.
>
> Regards
>
> Pavel

Hi Pavel,

Good catch! It looks like it comes directly from libxml2.

xmlDocPtr doc = xmlReadDoc(BAD_CAST "<foo><bar><val
x=\"y\">42</val></bar></foo>", NULL, NULL, 0 );
xmlBufferPtr buf = NULL;
xmlSaveCtxtPtr ctxt = NULL;

buf = xmlBufferCreate();
ctxt = xmlSaveToBuffer(buf, NULL, XML_SAVE_NO_DECL | XML_SAVE_FORMAT);

xmlSaveDoc(ctxt, doc);
xmlSaveClose(ctxt);

printf("'%s'",buf->content);

==>

'<foo>
  <bar>
    <val x="y">42</val>
  </bar>
</foo>
'

I'll do some digging to see if there is a good way to get rid of this
newline or if we need to chose a different dump function.

Thanks!

Best, Jim

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Dolgov 2023-04-23 12:25:35 Re: xmlserialize bug - extra empty row at the end
Previous Message Alexander Korotkov 2023-04-23 11:58:42 Re: duplicate function declaration in multirangetypes_selfuncs.c