Re: xmlserialize bug - extra empty row at the end

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, 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-24 08:29:27
Message-ID: 79b7c5b9-f033-dd16-3917-d0b2dc6b0d2b@uni-muenster.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 24.04.23 03:18, Tom Lane wrote:
> I wouldn't actually *use* pchomp here, because that induces an
> unnecessary
> copy of the result string. I had in mind more like copying pchomp's code
> to count up the trailing newline(s) and then pass a corrected length
> to cstring_to_text_with_len.
Changed.
> You could simplify matters by doing that in all cases, too. It should
> never find anything to remove in the non-indented case, but the check
> should be of negligible cost in context.

I'm not sure I understood it correctly.

The non-indented cases should never find anything and indented cases
with CONTENT strings do not add trailing newlines, so this is only
applicable with DOCUMENT .. INDENT, right?

Something like this would suffice?

if(xmloption_arg != XMLOPTION_DOCUMENT)
    result = (text *) xmlBuffer_to_xmltype(buf);
else
{
    int    len = xmlBufferLength(buf);
    const char *xmloutput = (const char *) xmlBufferContent(buf);

    while (len > 0 && xmloutput[len - 1] == '\n')
        len--;

    result = cstring_to_text_with_len(xmloutput, len);
}

If we really agree on manually removing the trailing newlines I will
open a CF entry for this.

Best, Jim

Attachment Content-Type Size
v1-0001-Remove-trailing-newlines-from-xmlserialize-indent.patch text/x-patch 5.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jesper Pedersen 2023-04-24 08:32:16 Re: New committers: Nathan Bossart, Amit Langote, Masahiko Sawada
Previous Message Andrey M. Borodin 2023-04-24 07:50:49 Re: New committers: Nathan Bossart, Amit Langote, Masahiko Sawada