Repository navigation
Conversation
HorlogeSkynet
left a comment
There was a problem hiding this comment.
Hey @pro-laxmi, thanks for you PR.
Could you address the following points :
- code comments in the
forloop shouldn't be removed io.StringIOwrapping oflinescould be replaced by alines.seek(os.SEEK_SET)if input file ends up being manually parsed the hard way (shouldn't occur much, and these files don't usually contain much data)- only
shlex.shlexcall should be wrapped in thetry..except ValueErrorblock
Thanks, bye 👋
66f5818 to
6a95f5f
Compare
|
Hey @HorlogeSkynet, thanks for the review and suggestions! I've updated the PR to address all three points:
Tested locally with both valid and malformed |
HorlogeSkynet
left a comment
There was a problem hiding this comment.
Hey @pro-laxmi ! Much better, thanks for the update.
Some more comments :
-
do you know a case/platform where
lines.seekwouldn't be available ? From documentation, it seemsTextIOBase.seekis cross-platform. -
do you mind adding a corresponding test case for this edge case ? This way code coverage would be kept.
Thanks, bye 👋
|
Hey @HorlogeSkynet! Thanks for following up. You're totally right about I also added a unit test case ( Thanks again! 😊 |
Summary of Changes
When
/etc/os-releaseis truncated, corrupted, or contains unclosed quotation marks (e.g.NAME="Fedora Linux),shlex.shlexraisesValueError("No closing quotation"). Currently, this unhandled exception crashes the entire program and any application or library importingdistro.Root Cause
_parse_os_release_contentcalledlist(lexer)without catchingValueError.Fix
Wrapped
shlexlexer tokenization in atry...except ValueErrorblock with an automatic fallback to robust line-by-line parsing (key, val = line.split("=", 1)), stripping surrounding quotes.Verification & Testing
Tested with malformed
os-releasestreams and unclosed quotes:Parsed successfully without crashing.