From 4acb9cf7344c343cd1adeb89e654dee734251f72 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:40:54 -0600 Subject: [PATCH 1/8] Wrap service command parameters in single quotes Should resolve issues with multi-word arguments, eg: > Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/nginx/bin/nginx -g daemon off; fails, but > Or, if you don't want/need a background service you can just run: '/opt/homebrew/opt/nginx/bin/nginx' '-g' 'daemon off;' succeeds --- Library/Homebrew/extend/os/mac/caveats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 6f9bc6639c..c0b8420586 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -37,7 +37,7 @@ class Caveats if f.plist_manual || f.service? command = if f.service? - f.service.command.join(" ") + f.service.command.map{ |arg| "'#{arg}'" }.join(" ") else f.plist_manual end From 1532c081f264a8c762b57bbfff0dd1eefc2acec5 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:46:57 -0600 Subject: [PATCH 2/8] Add space character in map (pacify brew style) --- Library/Homebrew/extend/os/mac/caveats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index c0b8420586..c3e2b8953b 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -37,7 +37,7 @@ class Caveats if f.plist_manual || f.service? command = if f.service? - f.service.command.map{ |arg| "'#{arg}'" }.join(" ") + f.service.command.map { |arg| "'#{arg}'" }.join(" ") else f.plist_manual end From 632b96780f525a7699d21932e30e68a08a69cf84 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:54:38 -0600 Subject: [PATCH 3/8] Test for single-quote service wrapper --- Library/Homebrew/test/caveats_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index f6d76521ac..06cd17ad52 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -124,7 +124,7 @@ describe Caveats do caveats = described_class.new(f).caveats expect(f.service?).to eq(true) - expect(caveats).to include("#{f.bin}/php test") + expect(caveats).to include("'#{f.bin}/php' 'test'") expect(caveats).to include("background service") end From 0c6266ee6037e1dfee01ef8c34f433d726d841e8 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:26:13 -0600 Subject: [PATCH 4/8] Only wrap multi-word arguments, add comment --- Library/Homebrew/extend/os/mac/caveats.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index c3e2b8953b..2a3f8a8029 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -37,7 +37,9 @@ class Caveats if f.plist_manual || f.service? command = if f.service? - f.service.command.map { |arg| "'#{arg}'" }.join(" ") + f.service.command + .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes + .join(" ") else f.plist_manual end From 87f5d989233476f364f9d15316ff68c6d3b6f922 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:26:34 -0600 Subject: [PATCH 5/8] Add test for multi-word service argument warpping --- Library/Homebrew/test/caveats_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 06cd17ad52..571e471016 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -124,7 +124,21 @@ describe Caveats do caveats = described_class.new(f).caveats expect(f.service?).to eq(true) - expect(caveats).to include("'#{f.bin}/php' 'test'") + expect(caveats).to include("#{f.bin}/php test") + expect(caveats).to include("background service") + end + + it "wraps multi-word service parameters" do + f = formula do + url "foo-1.0" + service do + run [bin/"nginx", "-g", "daemon off;"] + end + end + caveats = described_class.new(f).caveats + + expect(f.service?).to eq(true) + expect(caveats).to include("#{f.bin}/nginx -g 'daemon off;'") expect(caveats).to include("background service") end From 538a5d9e698763e3dc6eeae46535f032a5ff316e Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Tue, 7 Sep 2021 07:16:06 -0600 Subject: [PATCH 6/8] Accept @Rylan12 chained spacing conventions Co-authored-by: Rylan Polster --- Library/Homebrew/extend/os/mac/caveats.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 2a3f8a8029..2c84cf6ed7 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -38,8 +38,8 @@ class Caveats if f.plist_manual || f.service? command = if f.service? f.service.command - .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes - .join(" ") + .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes + .join(" ") else f.plist_manual end From a83877660b76d3c73c2c63b79541ee763ddc3a05 Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Tue, 7 Sep 2021 07:24:58 -0600 Subject: [PATCH 7/8] Revert "Accept @Rylan12 chained spacing conventions" This reverts commit 538a5d9e698763e3dc6eeae46535f032a5ff316e. --- Library/Homebrew/extend/os/mac/caveats.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 2c84cf6ed7..2a3f8a8029 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -38,8 +38,8 @@ class Caveats if f.plist_manual || f.service? command = if f.service? f.service.command - .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes - .join(" ") + .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes + .join(" ") else f.plist_manual end From dce6b77ad05ce23850fecdafb007cd261108a30a Mon Sep 17 00:00:00 2001 From: Benjamin Bolton <7146063+benpbolton@users.noreply.github.com> Date: Tue, 7 Sep 2021 10:10:26 -0600 Subject: [PATCH 8/8] Modify syntax for readability / consistency leverage map block and guard clause for readability thx @MikeMcQuaid --- Library/Homebrew/extend/os/mac/caveats.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 2a3f8a8029..7abc7655ad 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -37,9 +37,14 @@ class Caveats if f.plist_manual || f.service? command = if f.service? - f.service.command - .map { |arg| (arg =~ /\s/) ? "'#{arg}'" : arg } # wrap multi-word arguments in quotes - .join(" ") + f.service + .command + .map do |arg| + next arg unless arg.match?(/\s/) + + # quote multi-word arguments + "'#{arg}'" + end.join(" ") else f.plist_manual end