fix: handle '+' suffix in Bugzilla version strings#2
Open
AmSach wants to merge 1 commit into
Open
Conversation
Version strings like '5.2+' caused a ValueError when parsing because int() was called on '2+' instead of '2'. This change strips non-digit characters from each version part before conversion, so '5.2+' becomes (5, 2) instead of crashing with a traceback. Fixes python-bugzilla#238
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.
Fixed the bug described in issue python-bugzilla#238.
What was wrong
Version strings like "5.2+" caused a ValueError when parsing because the code called int("2+") which fails. The traceback was printed even though the fallback to version 5.0 worked.
How I fixed it
Changed _set_bz_version to strip non-digit characters from each version part before conversion using filter(str.isdigit, ...). Now "5.2+" correctly becomes (5, 2) without any traceback.
Before:
major, minor = [int(i) for i in version.split(".")[0:2]] # int("2+") -> ValueError
After:
parts = version.split(".")[0:2]
major = int("".join(filter(str.isdigit, parts[0]))) # "5" -> 5
minor = int("".join(filter(str.isdigit, parts[1]))) if len(parts) > 1 else 0 # "2+" -> 2
Tested by
Fixes python-bugzilla#238