piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 34 forks source link

Bad format string error if environment variable contains a % #54

Closed samwho closed 4 years ago

samwho commented 4 years ago

Describe the problem

If you use a TTY::Command and have a % in one of your environment variables, you will get a malformed format string error.

Steps to reproduce the problem

require 'tty-command'
cmd = TTY::Command.new
cmd.run("true", env: { "foo": "%16" })

Actual behaviour

Traceback (most recent call last):
        7: from /tmp/test.rb:3:in `<main>'
        6: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command.rb:104:in `run'
        5: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command.rb:185:in `execute_command'
        4: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command/process_runner.rb:41:in `run!'
        3: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command/printers/pretty.rb:20:in `print_command_start'
        2: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command/cmd.rb:121:in `to_command'
        1: from /Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command/cmd.rb:87:in `evars'
/Users/sam/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/tty-command-0.9.0/lib/tty/command/cmd.rb:87:in `%': malformed format string - %" (ArgumentError)

Expected behaviour

The command to return successfully with no error.

Describe your environment

samwho commented 4 years ago

Thanks so much for the quick turnaround on this. 🙏