From 22a3025f6e42ba25e168baf098c2b038bb99cbb9 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 3 Dec 2020 15:00:30 -0500 Subject: [PATCH] utils/pypi: return nil for non-pypi-packages from url --- Library/Homebrew/test/utils/pypi_spec.rb | 8 ++++++++ Library/Homebrew/utils/pypi.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Library/Homebrew/test/utils/pypi_spec.rb b/Library/Homebrew/test/utils/pypi_spec.rb index 20f423df52..25e733c192 100644 --- a/Library/Homebrew/test/utils/pypi_spec.rb +++ b/Library/Homebrew/test/utils/pypi_spec.rb @@ -172,5 +172,13 @@ describe PyPI do 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 diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index 7aeef94c29..365f79245f 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -110,8 +110,12 @@ module PyPI 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).