Skip to content

Commit

Permalink
Add valid chars test for the property of metadata (Modernizr#2601)
Browse files Browse the repository at this point in the history
* Add check for metadata.property to be lowercase

* Improve test for metadata.property values

* Refactor to keep polyfill test block
  • Loading branch information
adzo261 authored Sep 8, 2020
1 parent bd06d5a commit 3ccc7f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions test/node/lib/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 3ccc7f1

Please sign in to comment.