NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/54510 (libedit: filename completion broken in quote/double quaote)
The following reply was made to PR lib/54510; it has been noted by GNATS.
From: Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
To: Tom Lane <tgl%sss.pgh.pa.us@localhost>
Cc: NetBSD GNATS <gnats-bugs%netbsd.org@localhost>, Abhinav Upadhyay <abhinav%netbsd.org@localhost>,
Rin Okuyama <rokuyama.rk%gmail.com@localhost>
Subject: Re: lib/54510 (libedit: filename completion broken in quote/double quaote)
Date: Sat, 4 Jan 2020 12:39:29 +0530
On Sat, Jan 4, 2020 at 6:41 AM Tom Lane <tgl%sss.pgh.pa.us@localhost> wrote:
>
> Rin Okuyama <rokuyama.rk%gmail.com@localhost> writes:
> > (2) In fn_complete(), unescacpe_string() is invoked via
> > find_word_to_complete(). After that, the cursor position and end of
> > buffer are substituted to *point and *end, respectively, that are
> > calculated based on the string before unescaped. Doesn't this break
> > 3rd party softwares that provide completion_matches and/or
> > attempted_completion_function?
>
> Indeed, I was about to submit a new bug when I noticed this comment.
> This patch *does* break things for application-specific completion
> functions, because it strips backslashes from the input word whether
> that's appropriate or not. In the Postgres project's "psql"
> application, one of the things we want to do is tab-complete
> metacommands that start with backslashes, for instance "\pa<TAB>"
> should produce "\password". That works fine with readline, and it
> worked with libedit up till this patch; but now the completer just
> sees "pa" so it doesn't know what to do.
>
> Given the precedent of other nearby behaviors, maybe the right
> fix is to skip the unescaping when attempted_completion_function
> is non-NULL. I haven't tried to code that though.
>
> (We've worked around this, for the moment, by the expedient of
> ignoring the supplied text altogether in favor of looking into
> rl_line_buffer [1]. But that's an ugly hack so I'd like to
> revert it.)
>
> regards, tom lane
>
> [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=ddd87d564508bb1c80aac0a4439cfe74a3c203a9
Can you verify if this patch fixes the problem?
Index: filecomplete.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/filecomplete.c,v
retrieving revision 1.62
diff -u -r1.62 filecomplete.c
--- filecomplete.c 10 Dec 2019 19:42:09 -0000 1.62
+++ filecomplete.c 4 Jan 2020 07:07:25 -0000
@@ -583,10 +583,12 @@
static wchar_t *
find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer,
- const wchar_t * word_break, const wchar_t * special_prefixes,
size_t * length)
+ const wchar_t * word_break, const wchar_t * special_prefixes,
size_t * length,
+ int do_unescape)
{
/* We now look backwards for the start of a filename/variable word */
const wchar_t *ctemp = cursor;
+ wchar_t *temp;
size_t len;
/* if the cursor is placed at a slash or a quote, we need to find the
@@ -629,10 +631,16 @@
ctemp++;
}
*length = len;
- wchar_t *unescaped_word = unescape_string(ctemp, len);
- if (unescaped_word == NULL)
- return NULL;
- return unescaped_word;
+ if (!do_unescape) {
+ wchar_t *unescaped_word = unescape_string(ctemp, len);
+ if (unescaped_word == NULL)
+ return NULL;
+ return unescaped_word;
+ }
+ temp = el_malloc((len + 1) * sizeof(*temp));
+ (void) wcsncpy(temp, ctemp, len);
+ temp[len] = '\0';
+ return temp;
}
/*
@@ -662,6 +670,7 @@
size_t len;
int what_to_do = '\t';
int retval = CC_NORM;
+ int do_unescape = attempted_completion_function == NULL? 1: 0;
if (el->el_state.lastcmd == el->el_state.thiscmd)
what_to_do = '?';
@@ -677,7 +686,7 @@
li = el_wline(el);
temp = find_word_to_complete(li->cursor,
- li->buffer, word_break, special_prefixes, &len);
+ li->buffer, word_break, special_prefixes, &len, do_unescape);
if (temp == NULL)
goto out;
Home |
Main Index |
Thread Index |
Old Index