python-semanticversion icon indicating copy to clipboard operation
python-semanticversion copied to clipboard

Fix NPM spec less comparison with prerelease bug.

Open arjunaskykok opened this issue 5 years ago • 2 comments

This PR fixes this bug: https://github.com/rbarrois/python-semanticversion/issues/100.

arjunaskykok avatar Jun 13 '20 06:06 arjunaskykok

Thanks for the contribution! Could you explain why this fixes the bug? Ideally in comments or the commit message, but I can add it myself — as long as I understand it :D

rbarrois avatar Jun 15 '20 14:06 rbarrois

@rbarrois So without the fix, this is what happens.

>>> from semantic_version import NpmSpec, Version
>>> NpmSpec("<1.2.3-beta.7").clause
AnyOf(AllOf(Range('<', Version('1.2.3'), prerelease_policy='same-patch')), AllOf(Range('<', Version('1.2.3-beta.7'), prerelease_policy='same-patch'), Range('>=', Version('1.2.0'), prerelease_policy='always')))

Notice there is this clause AllOf(Range('<', Version('1.2.3'), prerelease_policy='same-patch')), so every prerelease (alpha-1,2,3,4,..., beta-1,2,3,4,...., rc-1,2,3,4,....) version always matches because versions 1.2.3-rc.4 or 1.2.3-alpha.7 or 1.2.3-beta.8 is always less than version 1.2.3. Basically, my fix removes this clause.

To be fair, I consider my patch as a quick fix, not as a holistic one. I don't fully understand how NPM spec matching engine works. :)

I mean I can update the PR to add a comment but I just need to make sure you are okay with my patch.

arjunaskykok avatar Jun 15 '20 14:06 arjunaskykok