From 0731da3b789b09ea60afa67d73d564d12ae74206 Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Mon, 30 Nov 2026 22:57:46 +0100 Subject: [PATCH 1/2] ci: runs Python 3.8/3.9 tests against Ubuntu 24.04 --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index aaf4d32..e6cdca0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,8 +32,6 @@ jobs: os: - "ubuntu-latest" python: - - "3.8" - - "3.9" - "3.10" - "3.11" - "3.12" @@ -42,6 +40,10 @@ jobs: include: - os: "ubuntu-22.04" python: "3.7" + - os: "ubuntu-24.04" + python: "3.8" + - os: "ubuntu-24.04" + python: "3.9" - os: "ubuntu-22.04" python: "pypy-3.10" - os: "macos-latest" From e7a64f5f1e41ae9c99083147a5d01dceaaee0ab1 Mon Sep 17 00:00:00 2001 From: pro-laxmi Date: Wed, 11 Nov 2026 23:13:09 +0530 Subject: [PATCH 2/2] fix: make os-release parser resilient to unclosed quote ValueError --- src/distro/distro.py | 18 +++++++++++++++--- tests/test_distro.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/distro/distro.py b/src/distro/distro.py index 90ceb87..9d5a068 100755 --- a/src/distro/distro.py +++ b/src/distro/distro.py @@ -1185,10 +1185,22 @@ def _parse_os_release_content(lines: TextIO) -> Dict[str, str]: A dictionary containing all information items. """ props = {} - lexer = shlex.shlex(lines, posix=True) - lexer.whitespace_split = True + try: + lexer = shlex.shlex(lines, posix=True) + lexer.whitespace_split = True + tokens = list(lexer) + except ValueError: + lines.seek(0) + tokens = [] + for line in lines: + line = line.strip() + if not line or line.startswith("#"): + continue + if "=" in line: + k, v = line.split("=", 1) + clean_v = v.strip("'\"") + tokens.append(f"{k}={clean_v}") - tokens = list(lexer) for token in tokens: # At this point, all shell-like parsing has been done (i.e. # comments processed, quotes and backslash escape sequences diff --git a/tests/test_distro.py b/tests/test_distro.py index 0131ba6..10f43f8 100644 --- a/tests/test_distro.py +++ b/tests/test_distro.py @@ -2647,6 +2647,20 @@ def test_kx_02(self) -> None: assert props.get("key1", None) is None assert props.get("key2", None) == "value 2" + def test_kx_03_unclosed_quotes(self) -> None: + props = self.distro._parse_os_release_content( + io.StringIO( + 'NAME="Ubuntu\n' + "ID=ubuntu\n" + 'VERSION_ID="24.04"\n' + "# Comment\n" + "MISSING_ASSIGNMENT\n" + ) + ) + assert props.get("name", None) == "Ubuntu" + assert props.get("id", None) == "ubuntu" + assert props.get("version_id", None) == "24.04" + @pytest.mark.skipif(not IS_LINUX, reason="Irrelevant on non-linux") class TestGlobal: