7 Bug-Reported-by: Albert Shih <Albert.Shih@obspm.fr>
8 Bug-Reference-ID: Wed, 5 Mar 2014 23:01:40 +0100
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00028.html
13 Patch (apply with `patch -p0'):
15 This patch changes the behavior of programmable completion to compensate
16 for two assumptions made by the bash-completion package. Bash-4.3 changed
17 to dequote the argument to programmable completion only under certain
18 circumstances, to make the behavior of compgen more consistent when run
19 from the command line -- closer to the behavior when run by a shell function
20 run as part of programmable completion. Bash-completion can pass quoted
21 arguments to compgen when the original word to be completed was not quoted,
22 expecting programmable completion to dequote the word before attempting
25 This patch fixes two cases:
27 1. An empty string that bash-completion passes to compgen as a quoted null
30 2. An unquoted word that bash-completion quotes using single quotes or
31 backslashes before passing it to compgen.
33 In these cases, since readline did not detect a quote character in the original
34 word to be completed, bash-4.3
36 *** ../bash-4.3/externs.h 2014-01-02 14:58:20.000000000 -0500
37 --- externs.h 2014-03-13 14:42:57.000000000 -0400
41 extern char *sh_backslash_quote_for_double_quotes __P((char *));
42 extern int sh_contains_shell_metas __P((char *));
43 + extern int sh_contains_quotes __P((char *));
45 /* declarations for functions defined in lib/sh/spell.c */
46 *** ../bash-4.3/lib/sh/shquote.c 2013-03-31 21:53:32.000000000 -0400
47 --- lib/sh/shquote.c 2014-03-13 14:42:57.000000000 -0400
55 + sh_contains_quotes (string)
60 + for (s = string; s && *s; s++)
62 + if (*s == '\'' || *s == '"' || *s == '\\')
67 *** ../bash-4.3/pcomplete.c 2013-08-26 15:23:45.000000000 -0400
68 --- pcomplete.c 2014-03-25 17:23:23.000000000 -0400
72 COMPSPEC *pcomp_curcs;
73 const char *pcomp_curcmd;
74 + const char *pcomp_curtxt;
80 dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
82 + /* Intended to solve a mismatched assumption by bash-completion. If
83 + the text to be completed is empty, but bash-completion turns it into
84 + a quoted string ('') assuming that this code will dequote it before
85 + calling readline, do the dequoting. */
86 + else if (iscompgen && iscompleting &&
87 + pcomp_curtxt && *pcomp_curtxt == 0 &&
88 + text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
89 + rl_filename_dequoting_function)
90 + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
91 + /* Another mismatched assumption by bash-completion. If compgen is being
92 + run as part of bash-completion, and the argument to compgen is not
93 + the same as the word originally passed to the programmable completion
94 + code, dequote the argument if it has quote characters. It's an
95 + attempt to detect when bash-completion is quoting its filename
96 + argument before calling compgen. */
97 + /* We could check whether gen_shell_function_matches is in the call
98 + stack by checking whether the gen-shell-function-matches tag is in
99 + the unwind-protect stack, but there's no function to do that yet.
100 + We could simply check whether we're executing in a function by
101 + checking variable_context, and may end up doing that. */
102 + else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
103 + pcomp_curtxt && text &&
104 + STREQ (pcomp_curtxt, text) == 0 &&
105 + variable_context &&
106 + sh_contains_quotes (text)) /* guess */
107 + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
109 dfn = savestring (text);
113 COMPSPEC *cs, *oldcs;
114 ! const char *oldcmd;
119 COMPSPEC *cs, *oldcs;
120 ! const char *oldcmd, *oldtxt;
127 oldcmd = pcomp_curcmd;
128 + oldtxt = pcomp_curtxt;
132 + pcomp_curtxt = word;
134 ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
139 pcomp_curcmd = oldcmd;
140 + pcomp_curtxt = oldtxt;
142 /* We need to conditionally handle setting *retryp here */
143 *** ../bash-4.3/patchlevel.h 2012-12-29 10:47:57.000000000 -0500
144 --- patchlevel.h 2014-03-20 20:01:28.000000000 -0400
147 looks for to find the patch level (for the sccs version string). */
149 ! #define PATCHLEVEL 9
151 #endif /* _PATCHLEVEL_H_ */
153 looks for to find the patch level (for the sccs version string). */
155 ! #define PATCHLEVEL 10
157 #endif /* _PATCHLEVEL_H_ */