compare-versions
compare-versions copied to clipboard
Wrong result by comparing versions with leading zero for patch.
Hello!
First of all thanks for such a great library!
I've revealed the problem with comparing versions with leading zero for the patch. Example:
compare('2.0.0123123', '2.0.13', '<=')
Expected: true Actual: false
As I understood the patches are compared with the following logic.
compare('2.0.0123123', '2.0.13', '<=')
// first operand patch: "123123"
// second operand patch: "13"
Number("0123123") <= Number("13") // false
Is it considered as expected behavior? Is there any possibility to compare strings instead?
Thanks
You are correct that leading zero is treated like Number('0123123')
as per https://semver.org/#spec-item-2
In your second example Number("0123123") <= Number("13")
, false
is indeed the expected behavior, so in your first example compare
should return false
because 123123
is larger than 13
.