mirror of
https://github.com/Modernizr/Modernizr.git
synced 2026-01-09 15:47:55 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user