Re: xmlserialize bug - extra empty row at the end - Mailing list pgsql-hackers

From Jim Jones
Subject Re: xmlserialize bug - extra empty row at the end
Date
Msg-id 79b7c5b9-f033-dd16-3917-d0b2dc6b0d2b@uni-muenster.de
Whole thread Raw
In response to xmlserialize bug - extra empty row at the end  (Pavel Stehule <pavel.stehule@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: "Andrey M. Borodin"
Date:
Subject: Re: New committers: Nathan Bossart, Amit Langote, Masahiko Sawada
Next
From: Jesper Pedersen
Date:
Subject: Re: New committers: Nathan Bossart, Amit Langote, Masahiko Sawada