Add an ugly workaround for a bug in some recent libedit versions.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Jan 2020 16:15:26 +0000 (11:15 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Jan 2020 16:15:26 +0000 (11:15 -0500)
Debian unstable is shipping a broken version of libedit: it de-escapes
words before passing them to the application's tab completion function,
preventing us from recognizing backslash commands.  Fortunately,
we have enough information available to dig the original text out of
rl_line_buffer, so ignore the string argument and do that.

I view this as a temporary workaround to get the affected buildfarm
members back to green in the wake of 7c015045b.  I hope we can get
rid of it once somebody fixes Debian's libedit; hence, no back-patch,
at least for now.

Discussion: https://postgr.es/m/20200103110128.GA28967@msg.df7cb.de

src/bin/psql/tab-complete.c

index 22717914c73bc79f2aa4bff1a1f66349c5f05c05..2fd88866c9fa45a584d286f77c6bccfc0f1677b7 100644 (file)
@@ -1447,7 +1447,13 @@ psql_completion(const char *text, int start, int end)
        NULL
    };
 
-   (void) end;                 /* "end" is not used */
+   /*
+    * Temporary workaround for a bug in recent (2019) libedit: it incorrectly
+    * de-escapes the input "text", causing us to fail to recognize backslash
+    * commands.  So get the string to look at from rl_line_buffer instead.
+    */
+   char       *text_copy = pnstrdup(rl_line_buffer + start, end - start);
+   text = text_copy;
 
 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
    rl_completion_append_character = ' ';
@@ -3859,6 +3865,7 @@ psql_completion(const char *text, int start, int end)
    /* free storage */
    free(previous_words);
    free(words_buffer);
+   free(text_copy);
 
    /* Return our Grand List O' Matches */
    return matches;