Commit 764dbbc
fix(hooks): make guard-main-checkout-bash agree with itself on backslashes and comment-named heredocs (#11278)
* fix(hooks): give split_segments() the backslash branch tokenize() already had (#11131)
Outside quotes a backslash escapes the next character, so an escaped `\"` opens no
quoted region. tokenize() modelled that; split_segments() did not. The disagreement
was fail-OPEN: the `"` behind the backslash opened a quote that never closed, every
separator after it went inert, the command collapsed into a single `echo` segment,
and a real `sed -i` into the shared checkout rode through as just another argument.
Measured probe, cwd inside the shared primary checkout:
echo \" ; sed -i s/a/b/ pkg/x.ts before: hook-exit=0 ALLOWED after: hook-exit=2
sed -i s/a/b/ pkg/x.ts (control) before: hook-exit=2 after: hook-exit=2
The mirror case #10247 (an escaped quote INSIDE a double-quoted word, a false BLOCK)
stays allowed — its twins are in the matrix next door and are unchanged.
Selftest: 100 -> 110 passed, 0 failed. Both directions pinned, including the
precision twins where the escape must NOT manufacture a target, and the same
command aimed at a linked worktree.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMTpSRF5CjMmQBFfPtPCwJ
* fix(hooks): a heredoc introducer named inside a comment introduces nothing (#11133)
strip_heredocs() ran on raw text and modelled neither quotes nor comments, so a
`<<EOF` occurring inside prose registered as a real introducer. The delimiter then
never appeared on a line of its own, the pending heredoc was never satisfied, and
every remaining line — including real commands — was dropped before either
quote-aware pass could see it. Fail-OPEN, and total for the rest of the command.
Measured probe, cwd inside the shared primary checkout:
"# use cat > /tmp/n <<EOF for notes" + sed -i s/a/b/ pkg/x.ts
before: hook-exit=0 ALLOWED after: hook-exit=2
"# plain prose comment" + same write (control)
before: hook-exit=2 after: hook-exit=2
Shape: the card's candidate 1 (narrow, keeps the existing pass order), not candidate 2
(one merged scanner). Only the DELIMITER SCAN consults the comment rule; the line
itself is passed through untouched, so the landed #10570 comment rule in the two
quote-aware passes stays the single implementation of it. The card's ordering hazard —
an unbalanced apostrophe in a heredoc BODY desynchronising a quote-aware comment
scanner — is structurally out of reach here: body lines are consumed by the `pending`
branch and never reach the scan. Pinned as its own case.
Selftest: 110 -> 121 passed, 0 failed. Both directions pinned, including a QUOTED `#`
on an introducing line (truncating there would expose the body as commands) and an
inline comment after a real introducer.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMTpSRF5CjMmQBFfPtPCwJ
* docs(hooks): the header enumerates four layers, not three (#11234)
PR #10406 correctly moved the count "Two" -> "Three" when it added layer 3.
PR #11129 (#10570) added layer 4 and left the count alone.
This header is the enumerated contract a reader checks a change against — and it is
the thing that told objectui's dev the two copies must not drift — so a miscount is
worth the one word. No logic, no self-test change: 121 passed, 0 failed, unchanged.
The objectui copy carries the miscount verbatim and deliberately (objectui#5459);
it ports downstream from here like any other drift item.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMTpSRF5CjMmQBFfPtPCwJ
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e353c9b commit 764dbbc
2 files changed
Lines changed: 112 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
173 | 197 | | |
174 | 198 | | |
175 | 199 | | |
| |||
199 | 223 | | |
200 | 224 | | |
201 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
202 | 252 | | |
203 | 253 | | |
204 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
121 | 167 | | |
122 | 168 | | |
123 | 169 | | |
| |||
130 | 176 | | |
131 | 177 | | |
132 | 178 | | |
| 179 | + | |
| 180 | + | |
133 | 181 | | |
134 | | - | |
| 182 | + | |
135 | 183 | | |
136 | 184 | | |
137 | 185 | | |
| |||
182 | 230 | | |
183 | 231 | | |
184 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
185 | 245 | | |
186 | 246 | | |
187 | 247 | | |
| |||
0 commit comments