Skip to content

Commit

Permalink
49353: Fix comments in sourced file.
Browse files Browse the repository at this point in the history
If the file was sourced from an interactive shell with
INTERACTIVE_COMMENTS not set, comments were not parsed.

Note there is a remaining edge case where the sourced
file is in fact entered at the comment line.
  • Loading branch information
Peter Stephenson committed Sep 9, 2021
1 parent 014fbfa commit db46c9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-09-09 Peter Stephenson <p.w.stephenson@ntlworld.com>

* 49353: Src/exe.c, Test/A01grammar.ztst: In sourced file,
always parse comments normally, ignoring INTERACTIVE_COMMENTS.

2021-09-08 Bart Schaefer <schaefer@zsh.org>

* 49391: Doc/Zsh/zle.yo: document default bracketed-paste bindings
Expand Down
2 changes: 1 addition & 1 deletion Src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4622,7 +4622,7 @@ getoutput(char *cmd, int qt)
char *s;

int onc = nocomments;
nocomments = (interact && unset(INTERACTIVECOMMENTS));
nocomments = (interact && !sourcelevel && unset(INTERACTIVECOMMENTS));
prog = parse_string(cmd, 0);
nocomments = onc;

Expand Down
9 changes: 9 additions & 0 deletions Test/A01grammar.ztst
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,12 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci
if : ${(e)a}; then echo x; fi
1:Status on bad substitution in if without else
?(eval):2: bad substitution

echo 'echo foo # comment
echo $(
echo bar # comment
)' >source_comments.zsh
$ZTST_testdir/../Src/zsh -f -o extendedglob -is -c '. ./source_comments.zsh'
0:Comments should be handled in command subst in interactively sourced files
>foo
>bar

0 comments on commit db46c9c

Please sign in to comment.