Skip to content

Commit f467e86

Browse files
authored
Merge pull request #192 from SAY-5/fix/option-isscript-null
fix(Option): guard isScript and isStyle against null resource
2 parents 1cae551 + d819f80 commit f467e86

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/Plugin/Option.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ class Option {
594594
* @return {boolean}
595595
*/
596596
isStyle(resource) {
597+
if (resource == null) return false;
597598
const [file] = resource.split('?', 1);
598599
return this.options.css.enabled && this.options.css.test.test(file);
599600
}
@@ -603,6 +604,7 @@ class Option {
603604
* @return {boolean}
604605
*/
605606
isScript(resource) {
607+
if (resource == null) return false;
606608
const [file] = resource.split('?', 1);
607609
return this.options.js.enabled && this.options.js.test.test(file);
608610
}

test/unit.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,18 @@ describe('plugin options unit tests', () => {
14811481
return expect(received).toEqual(true);
14821482
});
14831483

1484+
test('isScript null resource', () => {
1485+
option.options = {
1486+
js: {
1487+
enabled: true,
1488+
test: option.js.test,
1489+
},
1490+
};
1491+
1492+
const received = option.isScript(null);
1493+
return expect(received).toEqual(false);
1494+
});
1495+
14841496
test('getEntryPath', () => {
14851497
option.dynamicEntry = 'src/views/';
14861498
option.options.entry = option.dynamicEntry;

0 commit comments

Comments
 (0)