semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

Issue with hyphen sign when used in build and pre release section

Open KristianShishoev opened this issue 6 years ago • 4 comments

According to specification versions with hyphen sign in build section should be valid versions. In our project when we try to parse such versions we recieve exception. Example version: 1.2.3+123-abc

Also when there are more than one hyphen sign in pre release section version is not parsed correctly. For example if we have following version: 1.2.3-alpha-abc+123 when parsed it gets cut to 1.2.3-alpha-abc+123

KristianShishoev avatar Oct 16 '17 15:10 KristianShishoev

I confirm, the issue happens also in the subversion. ie: 1.2+ should be a valid requirement, according to:

http://ant.apache.org/ivy/history/2.1.0/settings/version-matchers.html

rupebac avatar Nov 16 '17 16:11 rupebac

We have the same issue with the NPM Requirement that pre-releases with a - within are not parsed correctly (NPE).

see tests

CCFenner avatar Feb 28 '18 15:02 CCFenner

I am seeing an issue here as well when parsing NPM Requirements. I'm using version 3.1.0

Example ^2.26.3-1 (this is something out there in the wild -- a library called wiremock-standalone)

When this is parsed, the first item on the list is a HYPHEN type token, so it goes down the 'upper and lower' path.

Screenshot 2020-09-23 at 11 17 18

On lines 336 and 337 of Requirement.java, you are trying to get two more parts, expecting that it's the left and right side of the range, but since there's a caret, you are getting the caret in token2.

In the Semver class constructor, calling 'trim()' on the value is causing an NPE.

When you use a non number i.e. ^2.26.3-beta, on the right hand side it correctly detects the type as NPM.

So the root cause for my issue is because it is interpreting the Requirement as the wrong type of range i.e. not a caret range, but a hyphen range.

mattcree avatar Sep 23 '20 10:09 mattcree

@KristianShishoev 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