On 09/20/2012 09:12 AM, Peter Eisentraut wrote:
On 9/20/12 2:01 AM, Heikki Linnakangas wrote:
Could you strip the CRs? Either at CREATE FUNCTION time, or when the
function is executed.
It has been proposed that the plsh handler should strip the CRs before
execution.  But I don't think that is a correct solution, because that
is user data which could be relevant.  It could be the case, for
example, that plsh is run on a Windows host with a particular shell that
requires CRLF line endings.



I confess I find it hard to take plsh terribly seriously, it just seems like a bad solution for practically any problem, when compared with, say, plperlu, and it seems so Unixish that the very idea of using it at all on Windows strikes me as crazy. Having said that, and devoted all of 5 minutes to looking at the code, I suggest that you make two changes:

        if (sourcecode[0] == '\n')
                sourcecode++;

would become:

        if (sourcecode[0] == '\n' || (sourcecode[0] == '\r' && sourcecode[1] == 
'\n'))
                sourcecode++;

and

        len = strcspn(rest, "\n");

would become:

        len = strcspn(rest, "\r\n");



Also, there is probably a pretty good case for opening the temp file using PG_BINARY_W 
rather than "w" so that Windows doesn't produce extra CRs for you (see recent 
discussion of this w.r.t. pg_upgrade).


cheers

andrew




--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to