From ad8d55d8ca12e1c3c7be0a30eb1c41bb589a13e2 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 12 Dec 2016 13:40:18 +0100 Subject: [PATCH 1/2] Update terminal-notifier.rb Fixes a bug that causes arguments starting with "-" to not be recognized --- Ruby/lib/terminal-notifier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ruby/lib/terminal-notifier.rb b/Ruby/lib/terminal-notifier.rb index c18af87..14feb9b 100644 --- a/Ruby/lib/terminal-notifier.rb +++ b/Ruby/lib/terminal-notifier.rb @@ -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| From 418396bfd093ab0b5a944bcff22c1ef311910ac4 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 12 Dec 2016 18:52:03 +0100 Subject: [PATCH 2/2] Update terminal-notifier_spec.rb Add test case for arguments starting with a dash. --- Ruby/spec/terminal-notifier_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Ruby/spec/terminal-notifier_spec.rb b/Ruby/spec/terminal-notifier_spec.rb index eaa59b7..226249c 100644 --- a/Ruby/spec/terminal-notifier_spec.rb +++ b/Ruby/spec/terminal-notifier_spec.rb @@ -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`