Skip to content

Commit fe33901

Browse files
committed
t: fix Lexer line count for $() inside double-quoted strings
scan_dqstring's post-loop newline counter re-counts newlines that were already counted during recursive parsing of $() bodies. This happens because scan_dollar returns text containing newlines (from multi-line command substitutions), and the catch-all counter at the end of scan_dqstring counts all of them again. Fix this by counting newlines inline as non-special characters are consumed, and removing the post-loop catch-all. Each newline is now counted exactly once: literal newlines at the inline match, line splices at the backslash handler, and $() newlines by scan_token during the recursive parse. This does not affect chainlint's output because chainlint annotates the original body text using byte offsets, not token line numbers. It matters for greplint.pl (introduced in a subsequent commit) which uses token line numbers to report the source location of bare grep assertions. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
1 parent a7e3fb1 commit fe33901

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

t/lib-shell-parser.pl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ sub scan_dqstring {
9393
my $b = $self->{buff};
9494
my $s = '"';
9595
while (1) {
96-
# slurp up non-special characters
97-
$s .= $1 if $$b =~ /\G([^"\$\\]+)/gc;
96+
# slurp up non-special characters; count newlines inline
97+
# so $() newlines (counted by scan_token during recursive
98+
# parsing) are not double-counted by a post-loop catch-all.
99+
if ($$b =~ /\G([^"\$\\]+)/gc) {
100+
$s .= $1;
101+
$self->{lineno} += () = $1 =~ /\n/sg;
102+
}
98103
# handle special characters
99104
last unless $$b =~ /\G(.)/sgc;
100105
my $c = $1;
@@ -111,7 +116,6 @@ sub scan_dqstring {
111116
}
112117
die("internal error scanning dq-string '$c'\n");
113118
}
114-
$self->{lineno} += () = $s =~ /\n/sg;
115119
return $s;
116120
}
117121

0 commit comments

Comments
 (0)