semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

Incorrect satisfies result for NPM type

Open hsz opened this issue 6 years ago • 2 comments

When I'm trying to check if 2.6.9 satisfies following NPM range:

<= 2.6.8 || >= 3.0.0 <= 3.0.1

I get true result.

As a workaround I have to split it by || and test both parts separately - then I get two falses:

val semver = Semver("2.6.9", Semver.SemverType.NPM)

val invalid = semver.satisfies("<= 2.6.8 || >= 3.0.0 <= 3.0.1") // true - INVALID ❌
val result = "<= 2.6.8 || >= 3.0.0 <= 3.0.1".split("||").any { semver.satisfies(it) } // false ✔️

hsz avatar Feb 12 '18 08:02 hsz

Your observation is correct. The input

<= 2.6.8 || >= 3.0.0 <= 3.0.1

is a range consisting of two comparator sets <= 2.6.8 and >= 3.0.0 <= 3.0.1 which both are false. Especially the second comparator set is false for 2.6.9.

Edit:

The list of tokens generated from this expression looks OK:

Token [type=OPENING, value=(]
Token [type=LTE, value=null]
Token [type=VERSION, value=2.6.8]
Token [type=CLOSING, value=)]
Token [type=OR, value=null]
Token [type=OPENING, value=(]
Token [type=GTE, value=null]
Token [type=VERSION, value=3.0.0]
Token [type=AND, value=null]
Token [type=LTE, value=null]
Token [type=VERSION, value=3.0.1]
Token [type=CLOSING, value=)]]

I am not sure if the list of tokens in RPN is OK, too:

Token [type=OR, value=null]
Token [type=AND, value=null]
Token [type=LTE, value=null]
Token [type=VERSION, value=2.6.8]
Token [type=GTE, value=null]
Token [type=VERSION, value=3.0.0]
Token [type=LTE, value=null]
Token [type=VERSION, value=3.0.1]

Is this correct?

ghost avatar Aug 22 '19 14:08 ghost

@hsz if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1

piotrooo avatar Jul 22 '22 22:07 piotrooo