Skip to content

Commit ed2792a

Browse files
authored
Fix case sensitivity in Repo class URL handling (#107)
Previously, the class docbuild.models.repo.Repo model treated URLs with different casing (e.g., ``github.com`` vs ``GitHub.com``) as unequal. This commit normalizes URLs to ensure that casing differences do not result in duplicate or distinct records for the same repository.
1 parent 94b0e27 commit ed2792a

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

changelog.d/107.bugfix.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fix case sensitivity in :class:`~docbuild.models.repo.Repo` handling.
2+
3+
Previously, the model treated URLs with different casing (e.g., ``github.com``
4+
vs ``GitHub.com``) as unequal. This commit normalizes URLs to ensure that
5+
casing differences do not result in duplicate or distinct records for the
6+
same repository.

src/docbuild/models/repo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ def __init__(self, value: str) -> None:
7878
ssh_match = self._SSH_PATTERN.match(value)
7979

8080
if 'https://' in value or 'http://' in value:
81-
parsed_original = urlparse(value)
82-
name = parsed_original.path.strip('/').lower().rsplit('.git', 1)[0]
83-
name = name.rstrip('/')
81+
parsed_original = urlparse(value.lower())
82+
name = parsed_original.path.strip('/').rsplit('.git', 1)[0]
8483
url = f'{parsed_original.scheme}://{parsed_original.netloc}/{name}.git'
8584
host = f'{parsed_original.scheme}://{parsed_original.netloc}'
8685
surl = f'{self._MAP_URL2SERVICE.get(host, "gh")}://{name}'

tests/models/test_repo.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from docbuild.models.repo import Repo
44

55

6-
@pytest.fixture
7-
def repo_url() -> str:
8-
return 'https://github.com/org/repo.git'
6+
# Use different spellings/casings of the same URL to test normalization
7+
@pytest.fixture(
8+
params=['https://github.com/org/repo.git', 'https://GitHub.com/ORG/repo.git']
9+
)
10+
def repo_url(request) -> str:
11+
return request.param
912

1013

1114
@pytest.mark.parametrize(
@@ -29,6 +32,12 @@ def repo_url() -> str:
2932
'org/repo_git',
3033
'https://github.com/org/repo_git.git',
3134
),
35+
# 6
36+
(
37+
'https://GitHub.com/ORG/repo_git.git/',
38+
'org/repo_git',
39+
'https://github.com/org/repo_git.git',
40+
),
3241
],
3342
)
3443
def test_repo_https(input_value, name, url):
@@ -54,6 +63,12 @@ def test_repo_https(input_value, name, url):
5463
'org/repo_git',
5564
'https://github.com/org/repo_git.git',
5665
),
66+
# 6
67+
(
68+
'[email protected]:org/repo_git/',
69+
'org/repo_git',
70+
'https://github.com/org/repo_git.git',
71+
),
5772
],
5873
)
5974
def test_repo_ssh(input_value, name, url):
@@ -106,6 +121,8 @@ def test_repo_abbreviation(input_value, name, url):
106121
('gh://org/repo.git', 'gh://org/repo'),
107122
# 8
108123
('gh://ORG/repo_git.git', 'gh://org/repo_git'),
124+
# 9
125+
('GH://ORG/repo_git.git', 'gh://org/repo_git'),
109126
],
110127
)
111128
def test_repo_with_surl(input_value, surl):
@@ -177,4 +194,4 @@ def test_repo_surl(repo_url):
177194

178195
def test_repo_str(repo_url):
179196
repo = Repo(repo_url)
180-
assert str(repo) == repo_url
197+
assert str(repo) == repo_url.lower()

0 commit comments

Comments
 (0)