Skip to content

Commit

Permalink
Merge pull request julienXX#189 from iRath96/patch-1
Browse files Browse the repository at this point in the history
Fix arguments starting with "-" being unrecognized
  • Loading branch information
julienXX authored Dec 12, 2016
2 parents e9b78b0 + 418396b commit e562037
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Ruby/lib/terminal-notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.version

def self.execute(verbose, options)
if available?
command = [BIN_PATH, *options.map { |k,v| v = v.to_s; ["-#{k}", "#{Shellwords.escape(v[0,1])}#{v[1..-1]}"] }.flatten]
command = [BIN_PATH, *options.map { |k,v| v = v.to_s; ["-#{k}", "#{v[0] == "-" ? " " : ""}#{Shellwords.escape(v[0,1])}#{v[1..-1]}"] }.flatten]
command = Shellwords.join(command) if RUBY_VERSION < '1.9'
result = ''
IO.popen(command) do |stdout|
Expand Down
7 changes: 7 additions & 0 deletions Ruby/spec/terminal-notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
IO.expects(:popen).with(command).yields(StringIO.new('output'))
TerminalNotifier.execute(false, :message => '[ZOMG] "OH YEAH"')
end

it "correctly escapes arguments that start with a dash" do
command = [TerminalNotifier::BIN_PATH, '-message', ' -kittens', '-title', ' -rule']
command = Shellwords.join(command) if RUBY_VERSION < '1.9'
IO.expects(:popen).with(command).yields(StringIO.new('output'))
TerminalNotifier.execute(false, :message => '-kittens', :title => '-rule')
end

it "returns the result output of the command" do
TerminalNotifier.execute(false, 'help' => '').should == `'#{TerminalNotifier::BIN_PATH}' -help`
Expand Down

0 comments on commit e562037

Please sign in to comment.