7 Bug-Reported-by: vw@vonwolff.de
8 Bug-Reference-ID: <20060123135234.1AC2F1D596@wst07.vonwolff.de>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2006-01/msg00090.html
13 There is a difference in behavior between bash-3.0 and bash-3.1 involving
14 parsing of single- and double-quoted strings occurring in old-style
15 command substitution. The difference has to do with how backslashes are
16 processed. This patch restores a measure of backwards compatibility while
17 the question of POSIX conformance and ultimately correct behavior is discussed.
19 THIS IS AN UPDATED PATCH. USE THIS COMMAND TO REVERSE THE EFFECTS OF
20 THE ORIGINAL PATCH. THE CURRENT DIRECTORY MUST BE THE BASH-3.1 SOURCE
23 patch -p0 -R < bash31-010.orig
25 Then apply this patch as usual.
29 *** ../bash-3.1/parse.y Fri Nov 11 23:14:18 2005
30 --- parse.y Thu Feb 23 08:21:12 2006
34 #define P_ALLOWESC 0x02
36 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
37 + #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
39 static char matched_pair_error;
45 int count, ch, was_dollar, in_comment, check_comment;
46 ! int pass_next_character, nestlen, ttranslen, start_lineno;
47 char *ret, *nestret, *ttrans;
48 int retind, retsize, rflags;
51 ! pass_next_character = was_dollar = in_comment = 0;
52 check_comment = (flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0;
54 /* RFLAGS is the set of flags we want to pass to recursive calls. */
58 int count, ch, was_dollar, in_comment, check_comment;
59 ! int pass_next_character, backq_backslash, nestlen, ttranslen, start_lineno;
60 char *ret, *nestret, *ttrans;
61 int retind, retsize, rflags;
64 ! pass_next_character = backq_backslash = was_dollar = in_comment = 0;
65 check_comment = (flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0;
67 /* RFLAGS is the set of flags we want to pass to recursive calls. */
70 start_lineno = line_number;
74 ! ch = shell_getc ((qc != '\'' || (flags & P_ALLOWESC)) && pass_next_character == 0);
76 ! ch = shell_getc (qc != '\'' && pass_next_character == 0);
82 start_lineno = line_number;
85 ! ch = shell_getc (qc != '\'' && pass_next_character == 0 && backq_backslash == 0);
94 /* Not exactly right yet */
95 ! else if (check_comment && in_comment == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || whitespace (ret[retind -1])))
98 if (pass_next_character) /* last char was backslash */
100 pass_next_character = 0;
104 /* Not exactly right yet */
105 ! else if MBTEST(check_comment && in_comment == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || whitespace (ret[retind - 1])))
108 + /* last char was backslash inside backquoted command substitution */
109 + if (backq_backslash)
111 + backq_backslash = 0;
112 + /* Placeholder for adding special characters */
115 if (pass_next_character) /* last char was backslash */
117 pass_next_character = 0;
122 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
123 pass_next_character++;
124 + else if MBTEST((flags & P_BACKQUOTE) && ch == '\\')
132 else if MBTEST(qc == '`' && (ch == '"' || ch == '\'') && in_comment == 0)
134 ! nestret = parse_matched_pair (0, ch, ch, &nestlen, rflags);
137 else if MBTEST(was_dollar && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
140 else if MBTEST(qc == '`' && (ch == '"' || ch == '\'') && in_comment == 0)
142 ! /* Add P_BACKQUOTE so backslash quotes the next character and
143 ! shell_getc does the right thing with \<newline>. We do this for
144 ! a measure of backwards compatibility -- it's not strictly the
145 ! right POSIX thing. */
146 ! nestret = parse_matched_pair (0, ch, ch, &nestlen, rflags|P_BACKQUOTE);
149 else if MBTEST(was_dollar && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
150 *** ../bash-3.1/patchlevel.h Wed Jul 20 13:58:20 2005
151 --- patchlevel.h Wed Dec 7 13:48:42 2005
154 looks for to find the patch level (for the sccs version string). */
156 ! #define PATCHLEVEL 9
158 #endif /* _PATCHLEVEL_H_ */
160 looks for to find the patch level (for the sccs version string). */
162 ! #define PATCHLEVEL 10
164 #endif /* _PATCHLEVEL_H_ */