mirror of
https://github.com/ansible/ansible.git
synced 2026-07-28 16:15:12 +02:00
Fix IndexError in apt_repository when validating short source lines (#87293)
Signed-off-by: Artem Muterko <artem@sopho.tech>
This commit is contained in:
@@ -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.
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user