Skip to content

Commit 3c959fa

Browse files
committed
avoid duplicate calls to env methods
1 parent 5fa26ba commit 3c959fa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ appear at the top.
66
## [Unreleased][]
77

88
* Your contribution here!
9+
* [#453](https://github.com/capistrano/sshkit/pull/453): fix and unify shell escaping for user/group/directory - [@grosser](https://github.com/grosser)
910

1011
## [1.18.2][] (2019-02-03)
1112

lib/sshkit/command.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ def environment_string
162162
end
163163

164164
def with(&_block)
165-
return yield unless environment_hash.any?
166-
"( export #{environment_string} ; #{yield} )"
165+
env_string = environment_string
166+
return yield if env_string.empty?
167+
"( export #{env_string} ; #{yield} )"
167168
end
168169

169170
def user(&_block)
170171
return yield unless options[:user]
171-
"sudo -u #{options[:user].to_s.shellescape} #{environment_string + " " unless environment_string.empty?}-- sh -c #{yield.shellescape}"
172+
env_string = environment_string
173+
"sudo -u #{options[:user].to_s.shellescape} #{env_string + " " unless env_string.empty?}-- sh -c #{yield.shellescape}"
172174
end
173175

174176
def in_background(&_block)

0 commit comments

Comments
 (0)