Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fetchcode/package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ def get_cocoapod_tags(spec, name):
data = response.strip()
for line in data.splitlines():
line = line.strip()
if line.startswith(name):
if line.startswith(name + "/"):
data_list = line.split("/")
if data_list[0] == name:
data_list.pop(0)
return data_list
return None
return []
except: # noqa: E722
return None

Expand Down
39 changes: 39 additions & 0 deletions tests/test_cocoapods_tag_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# fetchcode is a free software tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/fetchcode for support and download.

# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and http://aboutcode.org

# This software is licensed under the Apache License version 2.0.

# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at:
# http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import pytest

from fetchcode.package import get_cocoapods_data_from_purl
from fetchcode.package_util import get_cocoapod_tags


def test_cocoapod_tags_skip_packages_with_same_prefix(monkeypatch):
monkeypatch.setattr(
"fetchcode.utils.get_text_response", lambda url: "FooBar/9.0\nFoo/1.0/2.0\n"
)
assert get_cocoapod_tags("https://example.com/versions", "Foo") == ["1.0", "2.0"]


@pytest.mark.parametrize("response", ["FooBar/9.0\n", "Bar/1.0\n", ""])
def test_cocoapod_tags_return_empty_list_when_no_exact_match(monkeypatch, response):
monkeypatch.setattr("fetchcode.utils.get_text_response", lambda url: response)
assert get_cocoapod_tags("https://example.com/versions", "Foo") == []


@pytest.mark.parametrize("response", ["FooBar/9.0\n", "Bar/1.0\n", ""])
def test_cocoapods_data_yields_no_packages_when_no_exact_match(monkeypatch, response):
monkeypatch.setattr("fetchcode.utils.get_text_response", lambda url: response)
assert list(get_cocoapods_data_from_purl("pkg:cocoapods/Foo")) == []