Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semver regular expression does not follow Semantic Versioning standard format #32

Closed
petermichaux opened this issue Jun 1, 2013 · 6 comments

Comments

@petermichaux
Copy link

var semver = "\\s*[v=]*\\s*([0-9]+)"        // major
           + "\\.([0-9]+)"                  // minor
           + "\\.([0-9]+)"                  // patch
           + "(-[0-9]+-?)?"                 // build
           + "([a-zA-Z-+][a-zA-Z0-9-\.:]*)?" // tag

The above is the foundation of parsing in this module but it does not follow the format from the Semantic Version standard http://semver.org/

/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/

The first capturing group is "major".

The second capturing group is "minor".

The third capturing group is "patch".

The forth capturing group is "prerelease" (not including the preceding dash delimiter between patch and prerelease).

The "build" is non-capturing because it is not to be used in any comparisons.

@petermichaux
Copy link
Author

@isaacs I've proposed the inclusion of a BNF grammar in the Semantic Version standard. See semver/semver#110

@isaacs
Copy link
Contributor

isaacs commented Jun 15, 2013

Please test out v2.0. Either pull the master branch, or npm install semver@alpha.

There's still a few allowances for 1.2.3beta type prerelease tags without the -, because that's widely in use in npm. We'll have to start warning about it or something and then phase it out eventually if that's actually a problem.

@petermichaux
Copy link
Author

I think it is ok if 1.2.3beta is allowed if it is treated like 1.2.3-beta. Most importantly and more generally, as long as all versions that comply to the Semantic Version standard are treated properly then it is ok if node-semver has extensions to allow versions with other syntax.

@isaacs
Copy link
Contributor

isaacs commented Jun 17, 2013

In the latest code on master, every function will have an optional loose flag. In loose mode, it'll allow prerelease versions that don't start with -, and zero-leading numeric ids.

Moving forward, npm will use loose mode when evaluating others' package.json files, but strict mode when evaluating yours for publishing/etc. Maybe some day, we can remove loose mode.

@isaacs isaacs closed this as completed Jun 17, 2013
@bfloydgsn
Copy link

bfloydgsn commented May 5, 2016

Slightly better regex for 2.0.0-rc.2
([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-\-\.]+)?

@isaacs
Copy link
Contributor

isaacs commented May 5, 2016

@bfloydgsn You're commenting on a 3-year-old issue. This is historical, and not a good place to put new things.

If you'd like to make an improvement or have found a bug, please open a new PR or issue. Thanks.

@npm npm locked and limited conversation to collaborators May 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants