7 Bug-Reported-by: Greg Wooledge <wooledg@eeg.ccf.org>
8 Bug-Reference-ID: <20140418202123.GB7660@eeg.ccf.org>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/help-bash/2014-04/msg00004.html
13 Under certain circumstances, $@ is expanded incorrectly in contexts where
14 word splitting is not performed.
16 Patch (apply with `patch -p0'):
19 @@ -3248,8 +3248,10 @@ cond_expand_word (w, special)
20 if (w->word == 0 || w->word[0] == '\0')
21 return ((char *)NULL);
23 + expand_no_split_dollar_star = 1;
24 w->flags |= W_NOSPLIT2;
25 l = call_expand_word_internal (w, 0, 0, (int *)0, (int *)0);
26 + expand_no_split_dollar_star = 0;
29 if (special == 0) /* LHS */
30 @@ -7847,6 +7849,10 @@ param_expand (string, sindex, quoted, ex
31 We also want to make sure that splitting is done no matter what --
32 according to POSIX.2, this expands to a list of the positional
33 parameters no matter what IFS is set to. */
34 + /* XXX - what to do when in a context where word splitting is not
35 + performed? Even when IFS is not the default, posix seems to imply
36 + that we behave like unquoted $* ? Maybe we should use PF_NOSPLIT2
38 temp = string_list_dollar_at (list, (pflags & PF_ASSIGNRHS) ? (quoted|Q_DOUBLE_QUOTES) : quoted);
41 @@ -8816,6 +8822,7 @@ finished_with_string:
47 ifs_chars = (quoted_dollar_at || has_dollar_at) ? ifs_value : (char *)NULL;
49 @@ -8830,11 +8837,36 @@ finished_with_string:
50 regardless of what else has happened to IFS since the expansion. */
52 list = list_string (istring, " ", 1); /* XXX quoted == 1? */
53 + /* If we have $@ (has_dollar_at != 0) and we are in a context where we
54 + don't want to split the result (W_NOSPLIT2), and we are not quoted,
55 + we have already separated the arguments with the first character of
56 + $IFS. In this case, we want to return a list with a single word
57 + with the separator possibly replaced with a space (it's what other
59 + quoted_dollar_at is internal to this function and is set if we are
60 + passed an argument that is unquoted (quoted == 0) but we encounter a
61 + double-quoted $@ while expanding it. */
62 + else if (has_dollar_at && quoted_dollar_at == 0 && ifs_chars && quoted == 0 && (word->flags & W_NOSPLIT2))
64 + /* Only split and rejoin if we have to */
65 + if (*ifs_chars && *ifs_chars != ' ')
67 + list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
68 + tstring = string_list (list);
72 + tword = make_bare_word (tstring);
73 + if (tstring != istring)
75 + goto set_word_flags;
77 else if (has_dollar_at && ifs_chars)
78 list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
81 tword = make_bare_word (istring);
83 if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) || (quoted_state == WHOLLY_QUOTED))
84 tword->flags |= W_QUOTED;
85 if (word->flags & W_ASSIGNMENT)
89 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
90 looks for to find the patch level (for the sccs version string). */
92 -#define PATCHLEVEL 13
93 +#define PATCHLEVEL 14
95 #endif /* _PATCHLEVEL_H_ */