Don't elide blank lines when accumulating psql command history.
authorRobert Haas <rhaas@postgresql.org>
Wed, 16 Nov 2011 01:34:47 +0000 (20:34 -0500)
committerRobert Haas <rhaas@postgresql.org>
Wed, 16 Nov 2011 01:36:32 +0000 (20:36 -0500)
This can change the meaning of queries, if the blank line happens to
occur in the middle of a quoted literal, as per complaint from Tomas Vondra.

Back-patch to all supported branches.

src/bin/psql/input.c

index c7ef77d8cb1b9ad050866187eb58d14bea1b333a..ed2b4292a1e0a009611083825cf5efabecbc8f11 100644 (file)
@@ -86,10 +86,10 @@ void
 pg_append_history(const char *s, PQExpBuffer history_buf)
 {
 #ifdef USE_READLINE
-   if (useHistory && s && s[0])
+   if (useHistory && s)
    {
        appendPQExpBufferStr(history_buf, s);
-       if (s[strlen(s) - 1] != '\n')
+       if (!s[0] || s[strlen(s) - 1] != '\n')
            appendPQExpBufferChar(history_buf, '\n');
    }
 #endif