Skip to content

Commit fe574f3

Browse files
Handle absent CocoaPods versions and homepage metadata
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 27c4fc9 commit fe574f3

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/fetchcode/package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def get_cocoapods_data_from_purl(purl):
379379
hashed_path_underscore = hashed_path.replace("/", "_")
380380
file_prefix = "all_pods_versions_"
381381
spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt"
382-
data_list = get_cocoapod_tags(spec, name)
382+
data_list = get_cocoapod_tags(spec, name) or []
383383

384384
for tag in data_list:
385385
version_purl = PackageURL(type=purl.type, name=name, version=tag)
@@ -391,7 +391,7 @@ def get_cocoapods_data_from_purl(purl):
391391
base_url = "https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs"
392392
podspec_api_url = f"{base_url}/{hashed_path}/{name}/{tag}/{name}.podspec.json"
393393
podspec_api_response = get_response(podspec_api_url)
394-
podspec_homepage = podspec_api_response.get("homepage")
394+
podspec_homepage = podspec_api_response.get("homepage") or ""
395395

396396
if podspec_homepage.startswith("https://github.com/"):
397397
podspec_homepage_remove_gh_prefix = podspec_homepage.replace("https://github.com/", "")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# fetchcode is a free software tool from nexB Inc. and others.
2+
# Visit https://github.com/aboutcode-org/fetchcode for support and download.
3+
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# http://nexb.com and http://aboutcode.org
6+
7+
# This software is licensed under the Apache License version 2.0.
8+
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
# http://apache.org/licenses/LICENSE-2.0
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
from fetchcode import package
18+
19+
20+
def test_cocoapods_with_no_versions(monkeypatch):
21+
monkeypatch.setattr(package, "get_cocoapod_tags", lambda *args: None)
22+
assert list(package.get_cocoapods_data_from_purl("pkg:cocoapods/Example")) == []
23+
24+
25+
def test_cocoapods_without_homepage(monkeypatch):
26+
monkeypatch.setattr(package, "get_cocoapod_tags", lambda *args: ["1.0"])
27+
monkeypatch.setattr(package, "get_response", lambda url: {})
28+
sentinel = object()
29+
monkeypatch.setattr(package, "construct_cocoapods_package", lambda *args: sentinel)
30+
assert list(package.get_cocoapods_data_from_purl("pkg:cocoapods/Example")) == [sentinel]

0 commit comments

Comments
 (0)