compare-versions icon indicating copy to clipboard operation
compare-versions copied to clipboard

`satisfies()` using `1.*`-style wildcard evaluates to `false` for all non `0` patch versions

Open pichlermarc opened this issue 10 months ago • 1 comments

Hi, thanks for your work on this package! :slightly_smiling_face:

While troubleshooting, I came across some unexpected results. It looks like using a non-zero patch version will always evaluate to false if there's a wildcard for the minor version but not the patch version.

Some examples here to illustrate:

> const { satisfies } = require('compare-versions');
undefined
> satisfies('1.0.0', '1.*');
true
> satisfies('1.0.1', '1.*');
false
> satisfies('1.1.0', '1.*');
true
> satisfies('1.1.1', '1.*');
false

Additional info:

pichlermarc avatar Sep 29 '23 07:09 pichlermarc

Hey @pichlermarc,

I have taken a small look at the library and it looks like it is evaluating these conditions as false which the semvar library is evaluating to true

satisfies('3.0.3', '3.*')
satisfies('3.0.3', '3')

I believe this is because no operator is supplied so they are being compared with the = operator when "~" or "^" would provide the behaviour we need.

I have made a small PR https://github.com/omichelsen/compare-versions/pull/71 that changes this behaviour.

Ankcorn avatar Oct 01 '23 20:10 Ankcorn