diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index b3bb324d74..8955a6d31e 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -153,7 +153,7 @@ module RuboCop # Check whether value starts with the formula name and then a "/", " " or EOS. # If we're checking for "#{bin}", we also check for "-" since similar binaries also don't need interpolation. def path_starts_with?(path, starts_with, bin: false) - ending = bin ? "/| |-|$" : "/| |$" + ending = bin ? "/|-|$" : "/| |$" path.match?(/^#{Regexp.escape(starts_with)}(#{ending})/) end diff --git a/Library/Homebrew/test/rubocops/text/strict_spec.rb b/Library/Homebrew/test/rubocops/text/strict_spec.rb index 8ccd8ef678..92bca3593d 100644 --- a/Library/Homebrew/test/rubocops/text/strict_spec.rb +++ b/Library/Homebrew/test/rubocops/text/strict_spec.rb @@ -145,12 +145,11 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do RUBY end - it 'reports an offense if "\#{bin}" is in a `shell_output` string' do - expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + it 'does not report an offense if \#{bin}/foo and then a space and more text' do + expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula test do shell_output("\#{bin}/foo --version") - ^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo"` instead of `"\#{bin}/foo"` end end RUBY