Commit 7a6dce2
Escape bash matches per quoting context and fix the word-break boundary
A third review round, again verified by driving real TAB presses through a
pty and executing the resulting line, found the bash helper still corrupted
values in two situations.
The word-break scan treated every COMP_WORDBREAKS character in the word as
readline's replacement boundary, but readline does not split on one that is
backslash-escaped or inside quotes. Measuring what readline actually
replaces confirms it: `node:` and `a=b` keep a head, while `\(w`, `semi\;c`,
`a\:b` and any quoted word are replaced whole. Trimming a head readline was
not going to keep silently dropped the front of the value, so
`deploy --mode \(w<TAB>` ran with `whoami)`. The scan now tracks escaping
and quoting and only counts a boundary outside both.
Inside a quote the user opened, the match was inserted with no escaping for
that context, so `"$H<TAB>` produced a `$HOME` the shell then expanded, and
`'it<TAB>` produced an unterminated quote. Matches are now escaped for the
enclosing quote: the expandable characters in a double-quoted context, and
the `'\''` splice in a single-quoted one, since a single quote cannot be
escaped inside single quotes. The splice has to be built with a bare
assignment — within double quotes `\'` is not an escape, which double-escaped
it and left the shell at a continuation prompt.
Also make the helper name collision-proof. `sanitizeFunctionName` maps any
character to `_`, so a subcommand named `-choices` produced exactly
`_deploy__choices` and overwrote the helper; the name is now chosen against
the set of function names the script actually emits.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 0b31b88 commit 7a6dce2
2 files changed
Lines changed: 94 additions & 28 deletions
File tree
- packages/effect
- src/unstable/cli/internal/completions
- test/unstable/cli/completions
Lines changed: 72 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
19 | 37 | | |
20 | 38 | | |
21 | 39 | | |
| |||
65 | 83 | | |
66 | 84 | | |
67 | 85 | | |
68 | | - | |
| 86 | + | |
| 87 | + | |
69 | 88 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
76 | 99 | | |
77 | 100 | | |
78 | 101 | | |
| |||
83 | 106 | | |
84 | 107 | | |
85 | 108 | | |
86 | | - | |
87 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
88 | 112 | | |
89 | | - | |
| 113 | + | |
90 | 114 | | |
91 | 115 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
98 | 132 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
103 | 150 | | |
104 | | - | |
105 | | - | |
| 151 | + | |
| 152 | + | |
106 | 153 | | |
107 | 154 | | |
108 | 155 | | |
| |||
293 | 340 | | |
294 | 341 | | |
295 | 342 | | |
296 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
297 | 346 | | |
298 | 347 | | |
299 | 348 | | |
| |||
Lines changed: 22 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
244 | 248 | | |
245 | 249 | | |
246 | | - | |
| 250 | + | |
247 | 251 | | |
248 | 252 | | |
249 | | - | |
| 253 | + | |
250 | 254 | | |
251 | 255 | | |
252 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
253 | 270 | | |
254 | 271 | | |
255 | 272 | | |
| |||
0 commit comments