From 28f8cbe8daf8a8b96fef9df92fd6c63e0f342fc7 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 2 Apr 2023 23:00:14 +0100 Subject: [PATCH] Handle when the URL has interpolation: use `source` not `str_content` - We see this a lot in real Casks. --- Library/Homebrew/rubocops/cask/url.rb | 4 ++-- Library/Homebrew/test/rubocops/cask/url_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/rubocops/cask/url.rb b/Library/Homebrew/rubocops/cask/url.rb index 9ed9b85acb..ac20d2c275 100644 --- a/Library/Homebrew/rubocops/cask/url.rb +++ b/Library/Homebrew/rubocops/cask/url.rb @@ -24,7 +24,7 @@ module RuboCop def on_url_stanza(stanza) return if stanza.stanza_node.block_type? - url_string = stanza.stanza_node.first_argument.str_content + url_stanza = stanza.stanza_node.first_argument hash_node = stanza.stanza_node.last_argument return unless hash_node.hash_type? @@ -42,7 +42,7 @@ module RuboCop end # Skip if the URL and the verified value are the same. - next if value_node.str_content == url_string.delete_prefix("https://").delete_prefix("http://") + next if value_node.source == url_stanza.source.gsub(%r{^"https?://}, "\"") # Skip if the verified value ends with a slash. next if value_node.str_content.end_with?("/") diff --git a/Library/Homebrew/test/rubocops/cask/url_spec.rb b/Library/Homebrew/test/rubocops/cask/url_spec.rb index 93619d376b..1b768231dc 100644 --- a/Library/Homebrew/test/rubocops/cask/url_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/url_spec.rb @@ -175,6 +175,20 @@ describe RuboCop::Cop::Cask::Url do include_examples "does not report any offenses" end + context "when the url has interpolation in it and the verified url ends with a /" do + let(:source) do + <<~CASK + cask "foo" do + version "1.2.3" + url "https://example.com/download/foo-v\#{version}.dmg", + verified: "example.com/download/" + end + CASK + end + + include_examples "does not report any offenses" + end + context "when the url 'verified' value has a path component that doesn't end with a /" do let(:source) do <<~CASK