udem-dlteam / pnut

🥜 A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell
https://pnut.sh
BSD 2-Clause "Simplified" License
425 stars 14 forks source link

Fix quoting bug when preparing argv and when opening file #58

Closed laurenthuberdeau closed 4 months ago

laurenthuberdeau commented 4 months ago

Context

We never tested passing arguments with spaces to scripts generated by Pnut. Turns out we had missed quoting the $@ argument for make_argv and arguments with space were split.

This PR quotes the $@ argument and also adds quotes around the file in _open.

Testing

➜ ./examples/compiled/cp.sh file\ with\ space file\ with\ space2
➜ ./examples/compiled/cp.sh file\ with\ space "file with space3" 
➜  sha256sum file\ with\ space file\ with\ space2 file\ with\ space3
3531baeb96f92076bef7b33f33781ed9e41c769bde6a528351116ea0648a4531  file with space
3531baeb96f92076bef7b33f33781ed9e41c769bde6a528351116ea0648a4531  file with space2
3531baeb96f92076bef7b33f33781ed9e41c769bde6a528351116ea0648a4531  file with space3