Merge branch 'rtl-sdr' of https://github.com/roger-/packages
[feed/packages.git] / utils / bash / patches / 110-upstream-bash43-010.patch
1 BASH PATCH REPORT
2 =================
3
4 Bash-Release: 4.3
5 Patch-ID: bash43-010
6
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
10
11 Bug-Description:
12
13 Patch (apply with `patch -p0'):
14
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
23 completion.
24
25 This patch fixes two cases:
26
27 1. An empty string that bash-completion passes to compgen as a quoted null
28 string ('').
29
30 2. An unquoted word that bash-completion quotes using single quotes or
31 backslashes before passing it to compgen.
32
33 In these cases, since readline did not detect a quote character in the original
34 word to be completed, bash-4.3
35
36 --- a/externs.h
37 +++ b/externs.h
38 @@ -324,6 +324,7 @@ extern char *sh_un_double_quote __P((cha
39 extern char *sh_backslash_quote __P((char *, const char *, int));
40 extern char *sh_backslash_quote_for_double_quotes __P((char *));
41 extern int sh_contains_shell_metas __P((char *));
42 +extern int sh_contains_quotes __P((char *));
43
44 /* declarations for functions defined in lib/sh/spell.c */
45 extern int spname __P((char *, char *));
46 --- a/lib/sh/shquote.c
47 +++ b/lib/sh/shquote.c
48 @@ -311,3 +311,17 @@ sh_contains_shell_metas (string)
49
50 return (0);
51 }
52 +
53 +int
54 +sh_contains_quotes (string)
55 + char *string;
56 +{
57 + char *s;
58 +
59 + for (s = string; s && *s; s++)
60 + {
61 + if (*s == '\'' || *s == '"' || *s == '\\')
62 + return 1;
63 + }
64 + return 0;
65 +}
66 --- a/pcomplete.c
67 +++ b/pcomplete.c
68 @@ -183,6 +183,7 @@ ITEMLIST it_variables = { LIST_DYNAMIC,
69
70 COMPSPEC *pcomp_curcs;
71 const char *pcomp_curcmd;
72 +const char *pcomp_curtxt;
73
74 #ifdef DEBUG
75 /* Debugging code */
76 @@ -753,6 +754,32 @@ pcomp_filename_completion_function (text
77 quoted strings. */
78 dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
79 }
80 + /* Intended to solve a mismatched assumption by bash-completion. If
81 + the text to be completed is empty, but bash-completion turns it into
82 + a quoted string ('') assuming that this code will dequote it before
83 + calling readline, do the dequoting. */
84 + else if (iscompgen && iscompleting &&
85 + pcomp_curtxt && *pcomp_curtxt == 0 &&
86 + text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
87 + rl_filename_dequoting_function)
88 + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
89 + /* Another mismatched assumption by bash-completion. If compgen is being
90 + run as part of bash-completion, and the argument to compgen is not
91 + the same as the word originally passed to the programmable completion
92 + code, dequote the argument if it has quote characters. It's an
93 + attempt to detect when bash-completion is quoting its filename
94 + argument before calling compgen. */
95 + /* We could check whether gen_shell_function_matches is in the call
96 + stack by checking whether the gen-shell-function-matches tag is in
97 + the unwind-protect stack, but there's no function to do that yet.
98 + We could simply check whether we're executing in a function by
99 + checking variable_context, and may end up doing that. */
100 + else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
101 + pcomp_curtxt && text &&
102 + STREQ (pcomp_curtxt, text) == 0 &&
103 + variable_context &&
104 + sh_contains_quotes (text)) /* guess */
105 + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
106 else
107 dfn = savestring (text);
108 }
109 @@ -1522,7 +1549,7 @@ gen_progcomp_completions (ocmd, cmd, wor
110 COMPSPEC **lastcs;
111 {
112 COMPSPEC *cs, *oldcs;
113 - const char *oldcmd;
114 + const char *oldcmd, *oldtxt;
115 STRINGLIST *ret;
116
117 cs = progcomp_search (ocmd);
118 @@ -1545,14 +1572,17 @@ gen_progcomp_completions (ocmd, cmd, wor
119
120 oldcs = pcomp_curcs;
121 oldcmd = pcomp_curcmd;
122 + oldtxt = pcomp_curtxt;
123
124 pcomp_curcs = cs;
125 pcomp_curcmd = cmd;
126 + pcomp_curtxt = word;
127
128 ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
129
130 pcomp_curcs = oldcs;
131 pcomp_curcmd = oldcmd;
132 + pcomp_curtxt = oldtxt;
133
134 /* We need to conditionally handle setting *retryp here */
135 if (retryp)
136 --- a/patchlevel.h
137 +++ b/patchlevel.h
138 @@ -25,6 +25,6 @@
139 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
140 looks for to find the patch level (for the sccs version string). */
141
142 -#define PATCHLEVEL 9
143 +#define PATCHLEVEL 10
144
145 #endif /* _PATCHLEVEL_H_ */