hush: fix handling of empty heredoc EOF marker
function old new delta parse_stream 2609 2634 +25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
a732898fdd
commit
0f018b3070
4
shell/ash_test/ash-heredoc/heredoc_empty2.right
Normal file
4
shell/ash_test/ash-heredoc/heredoc_empty2.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
OK1
|
||||||
|
Ok:0
|
||||||
|
OK2
|
||||||
|
Ok:0
|
14
shell/ash_test/ash-heredoc/heredoc_empty2.tests
Executable file
14
shell/ash_test/ash-heredoc/heredoc_empty2.tests
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
unset a
|
||||||
|
|
||||||
|
# Heredoc with empty delimiter
|
||||||
|
cat <<- ""
|
||||||
|
OK1
|
||||||
|
|
||||||
|
echo Ok:$?
|
||||||
|
|
||||||
|
# Heredoc with empty delimiter
|
||||||
|
cat <<- ""
|
||||||
|
OK2
|
||||||
|
|
||||||
|
|
||||||
|
echo Ok:$?
|
44
shell/hush.c
44
shell/hush.c
@ -4001,24 +4001,34 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
if (ch != EOF)
|
if (ch != EOF)
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
if ((ch == '\n' || ch == EOF)
|
if (ch == '\n' || ch == EOF) {
|
||||||
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
check_heredoc_end:
|
||||||
) {
|
if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') {
|
||||||
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
||||||
heredoc.data[past_EOL] = '\0';
|
heredoc.data[past_EOL] = '\0';
|
||||||
debug_printf_parse("parsed heredoc '%s'\n", heredoc.data);
|
debug_printf_parse("parsed heredoc '%s'\n", heredoc.data);
|
||||||
return heredoc.data;
|
return heredoc.data;
|
||||||
}
|
}
|
||||||
while (ch == '\n') {
|
if (ch == '\n') {
|
||||||
o_addchr(&heredoc, ch);
|
/* This is a new line.
|
||||||
prev = ch;
|
* Remember position and backslash-escaping status.
|
||||||
|
*/
|
||||||
|
o_addchr(&heredoc, ch);
|
||||||
|
prev = ch;
|
||||||
jump_in:
|
jump_in:
|
||||||
past_EOL = heredoc.length;
|
past_EOL = heredoc.length;
|
||||||
do {
|
/* Get 1st char of next line, possibly skipping leading tabs */
|
||||||
ch = i_getch(input);
|
do {
|
||||||
if (ch != EOF)
|
ch = i_getch(input);
|
||||||
nommu_addchr(as_string, ch);
|
if (ch != EOF)
|
||||||
} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
|
nommu_addchr(as_string, ch);
|
||||||
|
} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
|
||||||
|
/* If this immediately ended the line,
|
||||||
|
* go back to end-of-line checks.
|
||||||
|
*/
|
||||||
|
if (ch == '\n')
|
||||||
|
goto check_heredoc_end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ch == EOF) {
|
if (ch == EOF) {
|
||||||
|
4
shell/hush_test/hush-heredoc/heredoc_empty2.right
Normal file
4
shell/hush_test/hush-heredoc/heredoc_empty2.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
OK1
|
||||||
|
Ok:0
|
||||||
|
OK2
|
||||||
|
Ok:0
|
14
shell/hush_test/hush-heredoc/heredoc_empty2.tests
Executable file
14
shell/hush_test/hush-heredoc/heredoc_empty2.tests
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
unset a
|
||||||
|
|
||||||
|
# Heredoc with empty delimiter
|
||||||
|
cat <<- ""
|
||||||
|
OK1
|
||||||
|
|
||||||
|
echo Ok:$?
|
||||||
|
|
||||||
|
# Heredoc with empty delimiter
|
||||||
|
cat <<- ""
|
||||||
|
OK2
|
||||||
|
|
||||||
|
|
||||||
|
echo Ok:$?
|
Loading…
x
Reference in New Issue
Block a user