Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
os:
- "ubuntu-latest"
python:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
Expand All @@ -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"
Expand Down
18 changes: 15 additions & 3 deletions src/distro/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading