Repository navigation
Validate negative version parts before lossy int() conversion - #533
SonicHedghog wants to merge 1 commit into
Conversation
int() truncates toward zero, so negative fractional inputs such as -0.5 passed the post-conversion validation as 0 and produced a valid but unintended 0.0.0 release version. Validate numeric parts for negativity before converting them, keeping the existing conversion behavior for all non-negative inputs. Fixes python-semver#531
|
@SonicHedghog I'm sorry, I was a bit slow to respond today. I realized too late that there is already PR#532 that covers the same that you already implemented. I already reviewed the former PR. Perhaps we can work on PR #532? as a base for this issue and close this one? If you have further ideas or suggestions, please add them there. I'm really sorry that I didn't tell you earlier, but it was a busy day. Nevertheless thanks for your contribution! 👍 |
|
No need to apologize — thanks for pointing it out! I agree it makes no sense to keep two parallel fixes for the same issue. I'll close this one and add my notes to #532 instead. I reviewed the diff there: the post-conversion check against the original value covers the truncation cases correctly, and the regression tests are thorough (nice catch covering |
|
Thank you very much for your help and understanding! Much appreciated! |
Fixes #531
Summary
int()truncates toward zero, so a negative fractional input such asVersion(-0.5)passed the post-conversion negativity check as0and produced the valid but unintended release0.0.0:This PR validates numeric parts for negativity before the lossy conversion, so negative fractional inputs now raise the documented
ValueError:The conversion behavior for all non-negative inputs is unchanged: positive fractional values still truncate exactly as before, string parts still convert as before, and the post-conversion checks (including the maximum-length checks) are untouched. Inputs that cannot be compared with zero fall back to the existing post-conversion validation.
Tests
major,minor, andpatch, including values below-1that were already caught after conversion