Add valid chars test for the property of metadata (#2601)

* Add check for metadata.property to be lowercase

* Improve test for metadata.property values

* Refactor to keep polyfill test block
This commit is contained in:
Aditya Zope
2020-09-08 13:53:44 +05:30
committed by GitHub
parent bd06d5a713
commit 3ccc7f1036
2 changed files with 20 additions and 0 deletions

View File

@@ -85,6 +85,14 @@ function metadata(cb) {
}
metadata.polyfills = pfs;
//metadata.property can only have lowercase alphanumeric and dashes
const properties = Array.isArray(metadata.property) ? metadata.property : [metadata.property];
properties.forEach(function (property) {
if (!property.match(/^[a-z0-9-]+$/)) {
throw new Error(metadata.name + ' : ' + property + ': Property can only have lowercase alphanumeric characters and dashes ' )
}
})
if (!metadata.async) {
metadata.async = false;
}

View File

@@ -102,6 +102,18 @@ describe('cli/metadata', function() {
expect(metadata).to.throw(/Minimal metadata not found/);
});
it('should throw if property contains uppercase characters and/or special symbols except dashes', function() {
var metadata = proxyquire(root + 'lib/metadata', {
'fs': {
'readFileSync': function() {
return '/*! { "name": "fake", "property": "U_pper-case123"}!*/ define([],';
}
}
});
expect(metadata).to.throw(/Property can only have lowercase alphanumeric characters and dashes/);
});
it('should throw if polyfill is incorrectly configured', function() {
var metadata = proxyquire(root + 'lib/metadata', {