Giter Club home page Giter Club logo

semver-regex's Introduction

semver-regex

Regular expression for matching semver versions

Install

npm install semver-regex

Usage

import semverRegex from 'semver-regex';

semverRegex().test('v1.0.0');
//=> true

semverRegex().test('1.2.3-alpha.10.beta.0+build.unicorn.rainbow');
//=> true

semverRegex().exec('unicorn 1.0.0 rainbow')[0];
//=> '1.0.0'

'unicorn 1.0.0 and rainbow 2.1.3'.match(semverRegex());
//=> ['1.0.0', '2.1.3']

Important

If you run the regex against untrusted user input, it's recommended to truncate the string to a sensible length (for example, 50). And if you use this in a server context, you should also give it a timeout.

I do not consider ReDoS a valid vulnerability for this package. It's simply not possible to make it fully ReDoS safe. It's up to the user to set a timeout for the regex if they accept untrusted user input. However, I'm happy to accept pull requests to improve the regex.

Related

  • find-versions - Find semver versions in a string
  • latest-semver - Get the latest stable semver version from an array of versions
  • to-semver - Get an array of valid, sorted, and cleaned semver versions from an array of strings
  • semver-diff - Get the diff type of two semver versions: 0.0.1 0.0.2patch
  • semver-truncate - Truncate a semver version: 1.2.31.2.0

semver-regex's People

Contributors

antongolub avatar bendingbender avatar dilijev avatar jelhan avatar s-a avatar sindresorhus avatar stroncium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

semver-regex's Issues

Docker Version Question

Hi,

I'm using this plugin for e.g. detecting the current installment version of docker. When running docker --version, I get this:

Docker version 17.03.1-ce-rc1, build 3476dbf

It seems the part of 17.03.1 is a semantic version, but using semverRegex().exec(/*...*/) it returns null.

Should be above version of docker be considered semantic? If so, it is possible to include this in the plugin?

Many thanks!

Wildcards?

Hey man, I was just about to do a PR to add support for wildcard semver ranges like 1.x and 1.0.*, but just wondered if there was a particular reason they weren’t in already?

Why are you exporting a function?

Just export the regex

Another thing is that there are a lot of useful regexps, but having them scattered is annoying. Wanna make an org/repo with all of them?

Lookbehind is not supported in all browsers (Safari)

Hi all,

First of all, thanks for this package!
I'm using it to check the version input in a Vue.js frontend. However, when opening a page in Safari (the new Internet Explorer), a lookbehind in regex is not supported.

I'll try and change the Regex so it'll work in Safari. However, like most developers, regex is a "hocus-pocus language", especially when they're long like this one.

Any suggestions are welcome!

Matches "0.0.0"

It's actually not clear if 0.0.0 is a valid version number under semver 2.0, but it seems wrong. The FAQ recommends starting development at 0.1.0, but that's not it in the spec, per se.

You regex allows leading zeroes

The regex allows leading zeroes in the major, minor and patch component of the version which is not allowed:

A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.

-- http://semver.org/

This regex is broken by design

Issuehunt badges

Test it against the following data set, it will pass some non-conforming strings and fail to pass some that are conforming.

1.2.3----RC-SNAPSHOT.12.9.1--.12
1.0.0+0.build.1-rc.10000aaa-kk-0.1
99999999999999999999999.999999999999999999.99999999999999999
Begin Invalid

1
1.2
1.2.3-0123
1.2.3-0123.0123
1.1.2+.123
+invalid
-invalid
-invalid+invalid
-invalid.01
alpha
alpha.beta
alpha.beta.1
alpha.1
alpha+beta
alpha_beta
alpha.
alpha..
beta
1.0.0-alpha_beta
-alpha.
1.0.0-alpha..
1.0.0-alpha..1
1.0.0-alpha...1
1.0.0-alpha....1
1.0.0-alpha.....1
1.0.0-alpha......1
1.0.0-alpha.......1
01.1.1
1.01.1
1.1.01
1.2
1.2.3.DEV
1.2-SNAPSHOT
1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788
1.2-RC-SNAPSHOT
-1.0.3-gamma+b7718
+justmeta
9.8.7+meta+meta
9.8.7-whatever+meta+meta
99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12

See semver/semver/issues/59.

stroncium earned $70.00 by resolving this issue!

Firefox - SyntaxError: invalid regexp group

It looks to me like this library was built with Server side usage in mind.

On the client side, It throws an error SyntaxError: invalid regexp group on Firefox, (works fine in Chrome)

The error seems to be coming from the lookbehind in the first group in the regexp (?<=^v?|\sv?).

Can you please add support for client side environments ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.