node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

semver.clean() returns null on some version strings

Open skenqbx opened this issue 14 years ago • 3 comments

Hello, i am not sure if this is a bug.

I noticed that semver.clean('5.4.0~oneric+3') returns null, I can reproduce this with any version string containing ~ or +.

My workaround currently is to replace ~ and + with - before passing it.

Could the function be corrected to either strip or ignore these characters?

skenqbx avatar Mar 28 '12 00:03 skenqbx

Yep. That's a bug.

isaacs avatar Mar 28 '12 03:03 isaacs

+1

A remove of all unneeded chars at beginning would be great, e. g. for #v1.2.3 too.

Quickfix (untested, but ok for my intend), change var semver

var semver = "\\s*(?:.+?)?\\s*([0-9]+)" // major (ignore all chars before number)
    + "\\.([0-9]+)"                     // minor
    + "\\.([0-9]+)"                     // patch
    + "(-[0-9a-zA-Z]+-?)?"        // build (e.g. "-rc1")
    + "(.+?)?\\s?"                          // tag (everything else, until \s)

But i am not sure about split build and tag, -alpha.1 returns build alpha tag .1

rottmann avatar Jun 05 '13 12:06 rottmann

Tilde for separating the prerelease isn't valid according to semver.org. Closing this.

isaacs avatar Jun 15 '13 03:06 isaacs