-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: write script and args to temp file and run that #78
Conversation
10ae363
to
d678908
Compare
… as a single string
return `''` | ||
} | ||
|
||
if (!/[\t\n\r "#$&'()*;<>?\\`|~]/.test(input)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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. |
seems to be working right? |
Literal carets are the problem character here, and the problems sometimes don't show up until you try lots of them. Try |
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 |
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. |
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 |
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
closes npm/cli#3067
closes npm/cli#3337
closes npm/cli#3600
closes npm/cli#3680
closes npm/cli#4873
closes npm/cli#4968
closes npm/cli#5004