]> git.ipfire.org Git - ipfire-3.x.git/blame - bash/patches/bash-5.0-patch-1.patch
bash: Update to 5.0
[ipfire-3.x.git] / bash / patches / bash-5.0-patch-1.patch
CommitLineData
6d9201b0
SS
1From 4d2e315490b778707b3a3afdfc514d5083a97a11 Mon Sep 17 00:00:00 2001
2From: Chet Ramey <chet.ramey@case.edu>
3Date: Fri, 18 Jan 2019 15:12:37 -0500
4Subject: [PATCH] Bash-5.0 patch 1: fix pathname expansion of directory names
5 containing backslashes
6
7---
8 bashline.c | 62 +++++++++++++++++++++++++++++++++++++++++---
9 lib/glob/glob_loop.c | 6 -----
10 patchlevel.h | 2 +-
11 3 files changed, 60 insertions(+), 10 deletions(-)
12
13diff --git a/bashline.c b/bashline.c
14index 2846aabf..75e79f1a 100644
15--- a/bashline.c
16+++ b/bashline.c
17@@ -231,6 +231,7 @@ static int bash_possible_variable_completions __P((int, int));
18 static int bash_complete_command __P((int, int));
19 static int bash_possible_command_completions __P((int, int));
20
21+static int completion_glob_pattern __P((char *));
22 static char *glob_complete_word __P((const char *, int));
23 static int bash_glob_completion_internal __P((int));
24 static int bash_glob_complete_word __P((int, int));
25@@ -1741,7 +1742,7 @@ bash_default_completion (text, start, end, qc, compflags)
26
27 /* This could be a globbing pattern, so try to expand it using pathname
28 expansion. */
29- if (!matches && glob_pattern_p (text))
30+ if (!matches && completion_glob_pattern ((char *)text))
31 {
32 matches = rl_completion_matches (text, glob_complete_word);
33 /* A glob expression that matches more than one filename is problematic.
34@@ -1850,7 +1851,7 @@ command_word_completion_function (hint_text, state)
35 glob_matches = (char **)NULL;
36 }
37
38- globpat = glob_pattern_p (hint_text);
39+ globpat = completion_glob_pattern ((char *)hint_text);
40
41 /* If this is an absolute program name, do not check it against
42 aliases, reserved words, functions or builtins. We must check
43@@ -3713,6 +3714,61 @@ bash_complete_command_internal (what_to_do)
44 return bash_specific_completion (what_to_do, command_word_completion_function);
45 }
46
47+static int
48+completion_glob_pattern (string)
49+ char *string;
50+{
51+ register int c;
52+ char *send;
53+ int open;
54+
55+ DECLARE_MBSTATE;
56+
57+ open = 0;
58+ send = string + strlen (string);
59+
60+ while (c = *string++)
61+ {
62+ switch (c)
63+ {
64+ case '?':
65+ case '*':
66+ return (1);
67+
68+ case '[':
69+ open++;
70+ continue;
71+
72+ case ']':
73+ if (open)
74+ return (1);
75+ continue;
76+
77+ case '+':
78+ case '@':
79+ case '!':
80+ if (*string == '(') /*)*/
81+ return (1);
82+ continue;
83+
84+ case '\\':
85+ if (*string == 0)
86+ return (0);
87+ }
88+
89+ /* Advance one fewer byte than an entire multibyte character to
90+ account for the auto-increment in the loop above. */
91+#ifdef HANDLE_MULTIBYTE
92+ string--;
93+ ADVANCE_CHAR_P (string, send - string);
94+ string++;
95+#else
96+ ADVANCE_CHAR_P (string, send - string);
97+#endif
98+ }
99+ return (0);
100+}
101+
102 static char *globtext;
103 static char *globorig;
104
105@@ -3877,7 +3933,7 @@ bash_vi_complete (count, key)
106 t = substring (rl_line_buffer, p, rl_point);
107 }
108
109- if (t && glob_pattern_p (t) == 0)
110+ if (t && completion_glob_pattern (t) == 0)
111 rl_explicit_arg = 1; /* XXX - force glob_complete_word to append `*' */
112 FREE (t);
113
114diff --git a/lib/glob/glob_loop.c b/lib/glob/glob_loop.c
115index 5f319cc2..7d6ae211 100644
116--- a/lib/glob/glob_loop.c
117+++ b/lib/glob/glob_loop.c
118@@ -54,17 +54,11 @@ INTERNAL_GLOB_PATTERN_P (pattern)
119 continue;
120
121 case L('\\'):
122-#if 0
123 /* Don't let the pattern end in a backslash (GMATCH returns no match
124 if the pattern ends in a backslash anyway), but otherwise return 1,
125 since the matching engine uses backslash as an escape character
126 and it can be removed. */
127 return (*p != L('\0'));
128-#else
129- /* The pattern may not end with a backslash. */
130- if (*p++ == L('\0'))
131- return 0;
132-#endif
133 }
134
135 return 0;
136diff --git a/patchlevel.h b/patchlevel.h
137index 1cd7c96c..40db1a32 100644
138--- a/patchlevel.h
139+++ b/patchlevel.h
140@@ -25,6 +25,6 @@
141 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
142 looks for to find the patch level (for the sccs version string). */
143
144-#define PATCHLEVEL 0
145+#define PATCHLEVEL 1
146
147 #endif /* _PATCHLEVEL_H_ */
148--
1492.17.2
150