Fix os-release parser capturing only the last character of quoted values - #40
Open
arpitjain099 wants to merge 1 commit into
Open
Fix os-release parser capturing only the last character of quoted values#40arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The /etc/os-release value pattern put the * quantifier outside the capture group, so the group rebinds each iteration and keeps only the final matched character: ID="ubuntu" parsed to "u" and VERSION_ID="22.04" to "4". The unquoted alternative also preceded the single-quote one and its \S* ate the surrounding quotes, leaving the singlequoted branch dead. These values feed the apt Contents-DB URL, the Docker base-image tag, and the cache key, so on a normal Linux host they were corrupted to single characters. Move the quantifiers inside the groups, order the quoted alternatives before the unquoted one, and extract a testable parse_os_release_line helper. Added a unit test. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
/etc/os-releaseline pattern inPackagingConfig.get_localplaces the*quantifier outside the capture group:r"\s*(?P<var>\S+)\s*=\s*(\"(?P<quoted>[^\"])*\"|(?P<unquoted>\S*)|\'(?P<singlequoted>[^\'])*\')\s*"Because
(?P<quoted>[^\"])*repeats the group, it rebinds on every iteration and keeps only the last matched character. On a normal host:ID="ubuntu"becomes"u"VERSION_ID="22.04"becomes"4"There is a second issue: the
unquotedalternative precedes the single-quote alternative and its\S*greedily consumes a single-quoted value including the quotes, so thesinglequotedbranch is dead.These values flow into the apt Contents-DB URL, the Docker base-image tag, and the cache key, so they get corrupted to single characters (the
VERSION_IDcase is masked when an unquotedVERSION_CODENAMEis present, since codename is preferred, but a quotedIDis not).Fix: move the quantifiers inside the groups and order the quoted alternatives before the unquoted one. I also extracted a small
parse_os_release_linehelper so this is unit-testable without touching/etc/os-release. Addedtest/test_os_release.py; ran it under Python 3.13 (3 passing), and confirmed the old pattern returns the last-character values.Thanks!