From 9d03a5b6a1580eeff70f530c955869c9113c679f Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 24 Jan 2020 19:09:23 +0300 Subject: [PATCH] allow 0 as numeric identifier, fixes #18 --- index.js | 2 +- test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 50076cd..78eaacf 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ 'use strict'; -module.exports = () => /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/ig; +module.exports = () => /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/ig; diff --git a/test.js b/test.js index 0883679..f02507e 100644 --- a/test.js +++ b/test.js @@ -83,3 +83,16 @@ test('#14, does not match sub-strings of longer semver-similar strings, respect t.notRegex(string, semverRegex()); } }); + +test('#18, allow 0 as numeric identifier', t => { + for (const string of [ + '0.2.3-alpha.10.beta+build.unicorn.rainbow', + '1.0.3-alpha.10.beta+build.unicorn.rainbow', + '1.2.0-alpha.10.beta+build.unicorn.rainbow', + '1.2.3-0.10.beta+build.unicorn.rainbow', + '1.2.3-alpha.0.beta+build.unicorn.rainbow', + '1.2.3-alpha.10.0+build.unicorn.rainbow' + ]) { + t.regex(string, semverRegex()); + } +});