Skip to content

Commit ddf3f64

Browse files
author
Chet Ramey
committed
Bash-5.0 patch 2: fix expansion of aliases whose value ends with an unquoted tab
1 parent 4d2e315 commit ddf3f64

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

parse.y

+4-1
Original file line numberDiff line numberDiff line change
@@ -2557,12 +2557,14 @@ next_alias_char:
25572557
if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE &&
25582558
pushed_string_list->flags != PSH_DPAREN &&
25592559
(parser_state & PST_COMMENT) == 0 &&
2560+
(parser_state & PST_ENDALIAS) == 0 && /* only once */
25602561
shell_input_line_index > 0 &&
2561-
shell_input_line[shell_input_line_index-1] != ' ' &&
2562+
shellblank (shell_input_line[shell_input_line_index-1]) == 0 &&
25622563
shell_input_line[shell_input_line_index-1] != '\n' &&
25632564
shellmeta (shell_input_line[shell_input_line_index-1]) == 0 &&
25642565
(current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"'))
25652566
{
2567+
parser_state |= PST_ENDALIAS;
25662568
return ' '; /* END_ALIAS */
25672569
}
25682570
#endif
@@ -2571,6 +2573,7 @@ pop_alias:
25712573
/* This case works for PSH_DPAREN as well */
25722574
if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
25732575
{
2576+
parser_state &= ~PST_ENDALIAS;
25742577
pop_string ();
25752578
uc = shell_input_line[shell_input_line_index];
25762579
if (uc)

parser.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define PST_REPARSE 0x040000 /* re-parsing in parse_string_to_word_list */
4848
#define PST_REDIRLIST 0x080000 /* parsing a list of redirections preceding a simple command name */
4949
#define PST_COMMENT 0x100000 /* parsing a shell comment; used by aliases */
50+
#define PST_ENDALIAS 0x200000 /* just finished expanding and consuming an alias */
5051

5152
/* Definition of the delimiter stack. Needed by parse.y and bashhist.c. */
5253
struct dstack {

patchlevel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
2626
looks for to find the patch level (for the sccs version string). */
2727

28-
#define PATCHLEVEL 1
28+
#define PATCHLEVEL 2
2929

3030
#endif /* _PATCHLEVEL_H_ */

y.tab.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -4873,12 +4873,14 @@ shell_getc (remove_quoted_newline)
48734873
if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE &&
48744874
pushed_string_list->flags != PSH_DPAREN &&
48754875
(parser_state & PST_COMMENT) == 0 &&
4876+
(parser_state & PST_ENDALIAS) == 0 && /* only once */
48764877
shell_input_line_index > 0 &&
4877-
shell_input_line[shell_input_line_index-1] != ' ' &&
4878+
shellblank (shell_input_line[shell_input_line_index-1]) == 0 &&
48784879
shell_input_line[shell_input_line_index-1] != '\n' &&
48794880
shellmeta (shell_input_line[shell_input_line_index-1]) == 0 &&
48804881
(current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"'))
48814882
{
4883+
parser_state |= PST_ENDALIAS;
48824884
return ' '; /* END_ALIAS */
48834885
}
48844886
#endif
@@ -4887,6 +4889,7 @@ shell_getc (remove_quoted_newline)
48874889
/* This case works for PSH_DPAREN as well */
48884890
if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
48894891
{
4892+
parser_state &= ~PST_ENDALIAS;
48904893
pop_string ();
48914894
uc = shell_input_line[shell_input_line_index];
48924895
if (uc)

0 commit comments

Comments
 (0)