From 37e4858275ccd1d7d52a966323ab17ae6efbd9f3 Mon Sep 17 00:00:00 2001 From: Jerome Simeon Date: Mon, 16 Dec 2019 10:56:24 -0500 Subject: [PATCH] fix(core) Stricter semver check for template metadata Signed-off-by: Jerome Simeon --- packages/cicero-core/src/metadata.js | 6 +++--- packages/cicero-core/test/metadata.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/cicero-core/src/metadata.js b/packages/cicero-core/src/metadata.js index d257754b..9d2951d2 100644 --- a/packages/cicero-core/src/metadata.js +++ b/packages/cicero-core/src/metadata.js @@ -76,11 +76,11 @@ class Metadata { throw new Error('Failed to find accordproject cicero version in package.json'); } - if(!semver.valid(semver.coerce(packageJson.accordproject.cicero))){ - throw new Error('The cicero version must be a valid semantic version (semver) number.'); + if(!semver.validRange(packageJson.accordproject.cicero)){ + throw new Error('The cicero version must be a valid semantic version (semver) range.'); } - if(!semver.valid(semver.coerce(packageJson.version))){ + if(!semver.valid(packageJson.version)){ throw new Error('The template version must be a valid semantic version (semver) number.'); } diff --git a/packages/cicero-core/test/metadata.js b/packages/cicero-core/test/metadata.js index fcd53d35..57642da9 100644 --- a/packages/cicero-core/test/metadata.js +++ b/packages/cicero-core/test/metadata.js @@ -155,7 +155,20 @@ describe('Metadata', () => { }, null, {})).should.throw('The template version must be a valid semantic version (semver) number.'); }); - it('should throw an error if cicero version is not valid semver ', () => { + it('should throw an error if template version is not valid semver (1.0)', () => { + return (() => new Metadata({ + name: 'template', + version: '1.0', + accordproject: { + template: 'clause', + ergo:'0.20.0-alpha.2', + cicero:ciceroVersion, + language: 'ergo' + }, + }, null, {})).should.throw('The template version must be a valid semantic version (semver) number.'); + }); + + it('should throw an error if cicero version is not valid semver range', () => { return (() => new Metadata({ name: 'template', version: '1.0.0', @@ -165,7 +178,7 @@ describe('Metadata', () => { ergo: 'BLEH', language: 'ergo' }, - }, null, {})).should.throw('The cicero version must be a valid semantic version (semver) number.'); + }, null, {})).should.throw('The cicero version must be a valid semantic version (semver) range.'); }); it('should throw an error if cicero version is not valid semver for current version of cicero', () => {