-
Notifications
You must be signed in to change notification settings - Fork 483
Mina::LocalHelpers::Local.invoke is broken for non-pretty term modes #309
Description
Mina::LocalHelpers::Local.invoke receives a Shellwords.escape'd command string that breaks Kernel.exec or Kernel.system.
Breaking example
- Create a
Minafilecontaining:
task :hello do
to :after_hook do
queue %[echo "hello"]
end
endNote: the default :term_mode setting is nil.
- Run
mina hello, outputs (or errs):
sh: echo "hello": command not found
! Command failed.
Failed with status 32512
Working example
- Use the same
Minafileas above, but first setterm_modeto:pretty:
set :term_mode, :pretty- Run
mina hello, output:
hello
Elapsed time: 0.01 seconds
So when either Kernel.exec or Kernel.system are called, the command string should not be shell escaped. It should be shell escaped when passed to Mina::ExecHelpers#pretty_system, which does Shellwords.shellsplit on it.
Proposed solution
Since Mina::LocalHelpers::Local.invoke is the responsible for switching between which shell execution method to use, it should be that method to decide whether to shell escape the command or not.
So change it to shell escape only when calling pretty_system and not escaping when calling Kernel methods and change all callers to send the command string as-is.
As far as I can see, the only caller is Mina::LocalHelpers#local.
Sidenote
Why the use of Kernel.exec? According to the docs, it replaces the current process by running the given external command. Is that expected behavior?