Commit Graph
7 Commits
Author SHA1 Message Date
L4XB 92b1b2a786 fix(hooks): read an ANSI-C quoted here-document delimiter without its $
Bash reads <<$'EOF' as the delimiter EOF, but the splitter took the $ into the word and waited for a $EOF line, so the body ran on and swallowed the commands after it. A $ before a quote now only starts the quoting.
2026-10-23 03:49:21 +02:00
L4XB ce2b27664f fix(hooks): check the commands that an expanded here-document body runs
Bash expands a here-document body unless part of its delimiter is quoted, and runs the $(...) and backquoted substitutions in it, with quotes as plain text. Leaving the whole body out of the segments hid those commands, so npm --version <<EOF with '$(npm run dev)' in the body was allowed. The commands of these substitutions are now segments of their own. An escaped substitution, or a body whose delimiter is quoted (<<'EOF', <<\EOF), stays data.
2026-10-23 03:13:14 +02:00
L4XB de87e6ec74 fix(hooks): leave here-document bodies out of the shell segments
A body attached to the segment of its command was still searched by the dev-server check. For npm --version <<EOF && cat, the body line npm run dev made the npm segment look like a dev server. A body is data, so it is no longer part of any segment. An empty delimiter (<<'') is a valid opener again, and its body ends at the first empty line.
2026-10-23 02:47:32 +02:00
L4XB d583576552 fix(hooks): read a here-document delimiter as a shell word and keep bodies with their command
The opener pattern read only an identifier, so <<EOF/END stored EOF, <<E"OF" stored E and <<123 was no opener at all. In each case the body was split into segments, or the line after it was swallowed. The delimiter is now read as a shell word with its quotes and backslashes removed, as Bash does. A body that follows an operator at the end of its line (cat <<EOF &&) was split off as a segment of its own. It now goes with the command that opened it.
2026-10-23 02:18:33 +02:00
L4XB 8dedd4ceb3 fix(hooks): read << as a here-document only outside comments and arithmetic
A << in a comment (echo ok # <<EOF) or an identifier shift ($((x << n))) was read as a here-document opener, so the following lines, npm run dev included, were swallowed into its body. A comment now runs to the end of its line and an arithmetic expression is copied whole, so neither opens a here-document nor splits at an operator. A delimiter line ending in \r (CRLF) now ends the body too.
2026-10-23 02:01:04 +02:00
L4XB 2eee66a6c1 fix(hooks): split shell segments at newlines, keeping here-document bodies whole
splitShellSegments() split at &&, ||, ; and & but not at a newline, so a multi-line command such as "cd app\nnpm run dev" was one segment led by cd, and the dev-server block let the dev server through. A newline now ends a segment. The body of a here-document (<<EOF, <<-EOF, <<'EOF') stays in the segment of the command that reads it, so a README written with cat <<EOF that mentions npm run dev is not blocked; a here-string (<<<) or a shift such as $((x << 2)) is not read as one.
2026-10-23 01:45:20 +02:00
zzzhizhi 177dd36e23 fix(hooks): allow tmux-wrapped dev server commands (#321)
* fix(hooks): fix shell splitter redirection/escape bugs, extract shared module

- Fix single & incorrectly splitting redirection operators (&>, >&, 2>&1)
- Fix escaped quotes (\", \') not being handled inside quoted strings
- Extract splitShellSegments into shared scripts/lib/shell-split.js
  to eliminate duplication between hooks.json, before-shell-execution.js,
  and pre-bash-dev-server-block.js
- Add comprehensive tests for shell splitting edge cases

* fix(hooks): handle backslash escapes outside quotes in shell splitter

Escaped operators like \&& and \; outside quotes were still being
treated as separators. Add escape handling for unquoted context.
2026-03-07 14:47:49 -08:00