| @@ -4001,24 +4001,34 @@ static char *fetch_till_str(o_string *as_string, |
| ch = i_getch(input); |
| if (ch != EOF) |
| nommu_addchr(as_string, ch); |
| - | if ((ch == '\n' || ch == EOF) |
| - | && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') |
| - | ) { |
| - | if (strcmp(heredoc.data + past_EOL, word) == 0) { |
| - | heredoc.data[past_EOL] = '\0'; |
| - | debug_printf_parse("parsed heredoc '%s'\n", heredoc.data); |
| - | return heredoc.data; |
| - | } |
| - | while (ch == '\n') { |
| - | o_addchr(&heredoc, ch); |
| - | prev = ch; |
| + | if (ch == '\n' || ch == EOF) { |
| + | check_heredoc_end: |
| + | if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') { |
| + | if (strcmp(heredoc.data + past_EOL, word) == 0) { |
| + | heredoc.data[past_EOL] = '\0'; |
| + | debug_printf_parse("parsed heredoc '%s'\n", heredoc.data); |
| + | return heredoc.data; |
| + | } |
| + | if (ch == '\n') { |
| + | /* This is a new line. |
| + | * Remember position and backslash-escaping status. |
| + | */ |
| + | o_addchr(&heredoc, ch); |
| + | prev = ch; |
| jump_in: |
| - | past_EOL = heredoc.length; |
| - | do { |
| - | ch = i_getch(input); |
| - | if (ch != EOF) |
| - | nommu_addchr(as_string, ch); |
| - | } while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t'); |
| + | past_EOL = heredoc.length; |
| + | /* Get 1st char of next line, possibly skipping leading tabs */ |
| + | do { |
| + | ch = i_getch(input); |
| + | if (ch != EOF) |
| + | 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) { |