Uh oh!
There was an error while loading. Please reload this page.
feat: write script and args to temp file and run that - #78
Conversation
Uh oh!
There was an error while loading. Please reload this page.
10ae363 to
d678908Compare… as a single string
| return `''` | ||
| } | ||
| if (!/[\t\n\r "#$&'()*;<>?\\`|~]/.test(input)) { |
There was a problem hiding this comment.
Just wanna be sure it's intentional that we're only looking for certain whitespace characters, and not using \s. Will approve assuming this is intentional.
There was a problem hiding this comment.
it was meant to be a list of each individual character that causes us to need single quotes to avoid expansion/keep the argument in one piece, the switch could likely be made but i felt like this was more explicit and clear
rhendric
commented
Jun 21, 2022
Did you test this with scripts that call executables from dependency packages? As we've discussed in the past, scripts that call executables like I still stand ready to assist with doing this the right way. The first step is still merging npm/exec#15, unless your plans have changed. |
nlf
commented
Jun 21, 2022
seems to be working right? |
rhendric
commented
Jun 21, 2022
Literal carets are the problem character here, and the problems sometimes don't show up until you try lots of them. Try |
nlf
commented
Jun 21, 2022
oh interesting.. so you're right, we do still have the problem with shim scripts. thank you for the reminder! the solution is to double up the escaping if the first thing we're calling is a batch file, right? i think it's likely we're not going to go down the road of re-escaping the script as defined in the package.json, but we can certainly grab the initial command and use that to trigger double escaping if we need to |
rhendric
commented
Jun 21, 2022
That'd be an improvement over this patch (which is already an improvement over the status quo), and quite possibly ‘good enough’. It is possible to write scripts for which this would do the wrong thing: consider If you want to enable correct escaping for scripts like the above, a true solution requires parsing the syntax of the script, not to add escape characters to it necessarily, but to determine the level of escaping that terminal arguments would need. If you think examples like the above are acceptably rare, then what you proposed is a reasonable shortcut. |
nlf
commented
Jun 21, 2022
I think this is likely to be the case. We certainly get few enough complaints about extremely complicated scripts for me to not feel like this further parsing is necessary. At least not right now. I'll have a pull request up that double escapes if the first command in the script resolves to a |
nlf
commented
Jun 21, 2022
i pushed #80 which i think gets us "close enough" for now at least. let me know your thoughts, if you have a moment to review. i really appreciate your continued eyes on this problem. i think if this series of changes isn't good enough, then we'll be circling back to adopting and modifying |
JSON.stringify()approachi've done my best in spelunking through open issues and verifying this approach fixes our reported issues, though it's very likely there are more than these:
closes#31
closes#60
closesnpm/cli#3067
closesnpm/cli#3337
closesnpm/cli#3600
closesnpm/cli#3680
closesnpm/cli#4873
closesnpm/cli#4968
closesnpm/cli#5004