From 6af4facf91460e8bb8564676684b9ae9f34ee936 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 10 Apr 2018 06:02:48 +0200 Subject: [PATCH] fix: refactor isValidSemver to avoid Invalid Version errors --- lib/util/semver.js | 4 +++- test/util/semver.spec.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/util/semver.js b/lib/util/semver.js index cacfa2bf65..b4e054df13 100644 --- a/lib/util/semver.js +++ b/lib/util/semver.js @@ -16,7 +16,6 @@ const { patch: getPatch, satisfies: matchesSemver, valid: isPinnedVersion, - validRange: isValidSemver, } = semver; const padRange = range => range + '.0'.repeat(3 - range.split('.').length); @@ -28,6 +27,9 @@ const getMajor = input => { const isRange = input => isValidSemver(input) && !isPinnedVersion(input); +// If this is left as an alias, inputs like "17.04.0" throw errors +const isValidSemver = input => semver.validRange(input); + module.exports = { getMajor, getMinor, diff --git a/test/util/semver.spec.js b/test/util/semver.spec.js index 18bd7b70f0..bfd5c79a4a 100644 --- a/test/util/semver.spec.js +++ b/test/util/semver.spec.js @@ -1,6 +1,9 @@ const semver = require('../../lib/util/semver'); describe('.isValidSemver(input)', () => { + it('should return null for irregular versions', () => { + expect(!!semver.isValidSemver('17.04.0')).toBe(false); + }); it('should support simple semver', () => { expect(!!semver.isValidSemver('1.2.3')).toBe(true); }); -- GitLab