Repository: Modernizr/Modernizr
Pull request #2601 (2020-09-06 20:14:51)

Add valid chars test for the property of metadata
Refers to issue #2595

As per our discussion, `metadata.property` can contain only `lowercase alphanumeric characters and dashes`.
PR adds a test for the same, which raises an error if `metadata.property` values doesn't have valid characters. 

Please have a look. Thanks!

codecov[bot]: # [Codecov](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=h1) Report
> Merging [#2601](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=desc) into [master](https://codecov.io/gh/Modernizr/Modernizr/commit/bd06d5a713f39e2af45d97df2ebfbb769be94ccd?el=desc) will **increase** coverage by `0.08%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/Modernizr/Modernizr/pull/2601/graphs/tree.svg?width=650&height=150&src=pr&token=pEqLyAS3IB)](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2601      +/-   ##
==========================================
+ Coverage   95.15%   95.23%   +0.08%     
==========================================
  Files           5        5              
  Lines         165      168       +3     
==========================================
+ Hits          157      160       +3     
  Misses          8        8              
```


| [Impacted Files](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/metadata.js](https://codecov.io/gh/Modernizr/Modernizr/pull/2601/diff?src=pr&el=tree#diff-bGliL21ldGFkYXRhLmpz) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=footer). Last update [bd06d5a...481569b](https://codecov.io/gh/Modernizr/Modernizr/pull/2601?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

rejas: Looks good. Nice work @adzo261 

Patch:
diff --git a/lib/metadata.js b/lib/metadata.js
index 6ff5474b..453d7406 100644
--- a/lib/metadata.js
+++ b/lib/metadata.js
@@ -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;
       }


Test patch:
diff --git a/test/node/lib/metadata.js b/test/node/lib/metadata.js
index e9041387..fdc5ced3 100644
--- a/test/node/lib/metadata.js
+++ b/test/node/lib/metadata.js
@@ -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', {