Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/pypi: return nil for non-pypi-packages from url #9413

Merged
merged 1 commit into from Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Library/Homebrew/test/utils/pypi_spec.rb
Expand Up @@ -172,5 +172,13 @@
it "updates url to new version" do
expect(described_class.update_pypi_url(old_package_url, "5.29.0")).to eq package_url
end

it "returns nil for invalid versions" do
expect(described_class.update_pypi_url(old_package_url, "0.0.0")).to eq nil
end

it "returns nil for non-pypi urls" do
expect(described_class.update_pypi_url("https://brew.sh/foo-1.0.tgz", "1.1")).to eq nil
end
end
end
4 changes: 4 additions & 0 deletions Library/Homebrew/utils/pypi.rb
Expand Up @@ -110,8 +110,12 @@ def <=>(other)
def update_pypi_url(url, version)
package = Package.new url, is_url: true

return unless package.valid_pypi_package?

_, url = package.pypi_info(version: version)
url
rescue ArgumentError
nil
end

# Return true if resources were checked (even if no change).
Expand Down