Fix IndexError in apt_repository when validating short source lines (#87293)

Signed-off-by: Artem Muterko <artem@sopho.tech>
This commit is contained in:
Archy
2026-07-24 14:51:56 -04:00
committed by GitHub
parent 5482e6e6c9
commit 76884711a6
3 changed files with 12 additions and 0 deletions
@@ -0,0 +1,4 @@
bugfixes:
- apt_repository - treat a source line whose type is valid but which has fewer
than two following fields (for example a bare ``deb``) as invalid instead of
raising an ``IndexError`` while parsing sources.list files.
+3
View File
@@ -324,6 +324,9 @@ class SourcesList(object):
else:
remaining_parts = parts[1:]
if len(remaining_parts) < 2:
return False
# According to `sources.list(5)` man pages, only four fields are mandatory:
# * `Types` either `deb` or/and `deb-src`
# * `URIs` to repositories holding valid APT structure (unclear if multiple are allowed)
@@ -25,6 +25,11 @@ from ansible.modules.apt_repository import SourcesList
True,
id="comment_at_end_line"
),
pytest.param("deb", False, id="type_only"),
pytest.param("deb https://example.com/debian", False, id="uri_without_suite"),
pytest.param("deb [arch=amd64] https://example.com/debian", False, id="option_uri_without_suite"),
pytest.param("", False, id="empty_source"),
pytest.param("deb [arch=amd64 http://example.com/debian focal main", False, id="unclosed_option_bracket"),
]
)
def test_validate(line, expected):