-
Notifications
You must be signed in to change notification settings - Fork 255
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
Use string interpolation for environment variables to avoid escaping issues with sprintf #280
Conversation
I've not been able to run the functional tests. Vagrant is estimating 2h30 to download |
Tried again this morning - much faster download. Functional tests are 👍. |
@leehambley Sorry to nudge - any thoughts on this? I'll bring it up to date if you're 👍 :) |
There's a bit of disagreement about how to do shell escaping. Check the issue list, someone is holding up the example that we escape parts of the env vars, and therefore we should do the same in command names and arguments. The problem is though there's no way to do it right, so I'm tempted to just not do it at all, and have people use the lower level APIs and call shell words escape themselves. |
That's fair. I suspect trying to escape entire commands would just result in pain (e.g. how do you know if a user wants a character to be interpreted literally or not). In the case of this PR, I felt it was justified as it's escaping for an internal use of Going back to environment variables - the reason I wrote that #250 is that
I've been doing some thinking since then, and maybe there's a third option which gets SSHKit out of this situation of trying to escape/quote things correctly. How would you feel about an option like Would love to hear your thoughts. |
I'll start here, since this could be the crux of the problem! Actually Cap2 allowed you to define the shell, that included This, though I believe would solve all the issues, as you could wrap Cap in a login shell, wrap cap in a Your thoughts? |
Sounds spot on! As you point out, there's really subtle escaping to get right with that approach, but it seems flexible enough to cover a lot of use-cases people have. If it's doable, it feels like the right thing(™). I'd love to help out if you can excuse my free time being quite sporadic. Is a wiki page the place to start? Would be nice to have the feature written out and start coming up with a list of problems/edge-cases to tackle. |
No worries, mine too. You'll find cloning SSHKit and running I could imagine a new part of the command map, not Caveats I see:
Heads-up: The default hashes on the command map use this slightly opaque technique http://ruby-doc.org/core-1.9.3/Hash.html#method-c-new described in more detail in the README, but quoted here:
Finally, you'll also have to check the |
So apologies for the year's gap, but this just appeared on my todo list again as we're maintaining an internal monkey-patch that applies this change. The code in this PR feels kinda orthogonal to fixing escaping of environment variables - it's escaping strings for reasons internal to the code, rather than for bash. Do you have any thoughts on merging this in the interim? I'm happy to rebase and re-run tests. |
I'm late to the game on this issue, but perhaps a simpler solution would be to remove sprintf("( export #{environment_string} ; %s )", yield) with this: "( export #{environment_string} ; #{yield} )" Are there any subtle differences between |
None, I don't think. (Sent from my Nexus 6, please forgive typos!) On Oct 3, 2016 21:16, "Matt Brictson" [email protected] wrote:
|
@Sinjo What do you think about changing this PR to use the |
It sounds good to me! Updating the PR now. |
Thanks! ✨ |
All done, rebased, tests still passing. Would you like those commits squashed before merge? |
Ah, never mind. :P |
Yep, I took care of the squashing. 👍 |
## [1.12.0][] (2017-02-10) ### Breaking changes * None ### New features * Add `SSHKit.config.default_runner_config` option that allows overriding default runner configs. ## [1.11.5][] (2016-12-16) ### Bug fixes * Do not prefix `exec` command [PR #378](capistrano/sshkit#378) @dreyks ## [1.11.4][] (2016-11-02) * Use string interpolation for environment variables to avoid escaping issues with sprintf [PR #280](capistrano/sshkit#280) @Sinjo - Chris Sinjakli
@leehambley Following on from the discussion in #264.
user
also runs the environment variables throughsprintf
, so I've applied the same fix there.