Skip to content

Commit

Permalink
Handle when the URL has interpolation: use source not str_content
Browse files Browse the repository at this point in the history
- We see this a lot in real Casks.
  • Loading branch information
issyl0 committed Apr 2, 2023
1 parent 41c3598 commit 28f8cbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/rubocops/cask/url.rb
Expand Up @@ -24,7 +24,7 @@ class Url < Base
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?

Expand All @@ -42,7 +42,7 @@ def on_url_stanza(stanza)
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?("/")

Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/rubocops/cask/url_spec.rb
Expand Up @@ -175,6 +175,20 @@
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
Expand Down

0 comments on commit 28f8cbe

Please sign in to comment.