fix: run prettier without a shell so filenames can't be executed#840
fix: run prettier without a shell so filenames can't be executed#840ryanwaits wants to merge 1 commit into
Conversation
|
Yeah this is a weird one eh? Maybe it's time to hand this off to a subagent to come up with the environment specific linter calls... We've had quite a few issues with these tools |
|
yeah the step shells out and it assumes prettier, and this only fixes the shelling out. the assumption is the bigger one imo. detecting the project's own formatter and running its binary out of node_modules feels like the right shape. happy to pick that up as a follow-up, though it probably warrants its own issue rather than growing this one? just lmk! |
|
Yeah, I'm gonna review this one as is. That is a separate issue all together. |
Fixes #800
Problem
Two bugs, and the one that isn't in the issue is the one that bites everyone.
The parser breaks before the shell sees a path. git C-quotes anything with a space or a non-ASCII byte,
/^\S+\s+(\S+)/only takes the first token, and renames yield the pre-rename path. So an ordinary rename plus a delete is enough: prettier getskeep.ts oldname.ts "to, the shell hits an unterminated quote, exit 2, nothing formatted.Then the reported bug. Filenames are interpolated into
exec. Spaces get quoted by git, but;,>,|and$don't, so a file nameda.ts;>PWNEDexecutes the redirect.Fix
Read
git status --porcelain=v1 -zand pass filenames as argv entries instead of interpolating them into a shell command.-zis git's documented machine-parsing format: no quoting, reversed rename order, guaranteed stable across versions and user config. Keep the post-rename path, skip deletes. Run prettier's CLI underprocess.execPathviaexecFilewithshell: false, plus--so a leading-dash filename isn't read as a flag.execFile('npx', ...)was the smaller diff, but it puts the shell back on Windows, wherenpxisnpx.cmd. Resolving prettier fromnode_modulesavoids that everywhere.Testing
10 new tests in
setup-utils.test.ts; 8 fail onmain. End to end on a repo with a rename, a delete,with space.tsanda.ts;>PWNED: before, shell error, nothing formatted. After, exit 0, all formatted, noPWNED. Build, tests and lint are green.Caveat
Prettier declared but not resolvable from
node_modulesnow returns quietly instead of lettingnpxfetch it. That covers running beforeinstall, and Yarn PnP, which has nonode_modulesat all. Happy to add annpxfallback on non-Windows, whereexecFilecan reach it without a shell.