diff options
-rw-r--r-- | main_background.js | 7 | ||||
-rw-r--r-- | pattern_utils.js | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/main_background.js b/main_background.js index df5be8e..9f8b0d6 100644 --- a/main_background.js +++ b/main_background.js @@ -27,6 +27,7 @@ const { Storage, ListStore, hash } = require('./common/Storage'); const { ListManager } = require('./bg/ListManager'); const { ExternalLicenses } = require('./bg/ExternalLicenses'); const { licenses } = require('./license_definitions'); +const { patternUtils } = require('./pattern_utils'); console.log('main_background.js'); /** @@ -540,8 +541,8 @@ function evaluate(script, name) { return new RegExp('(?:[^\\w\\d]|^|(?:' + arith_operators + '))' + object + '(?:\\s*?(?:[\\;\\,\\.\\(\\[])\\s*?)', 'g'); } reserved_object_regex('window'); - var ml_comment = /\/\*([\s\S]+?)\*\//g; - var il_comment = /\/\/.+/gm; + const ml_comment = /\/\*([\s\S]+?)\*\//g; + const il_comment = /\/\/.+/gm; var temp = script.replace(/'.+?'+/gm, '\'string\''); temp = temp.replace(/".+?"+/gm, '"string"'); temp = temp.replace(ml_comment, ''); @@ -616,7 +617,7 @@ function license_read(scriptSrc, name, external = false) { let partsAccepted = false; function checkTriviality(s) { - if (!s.trim()) { + if (!patternUtils.removeJsComments(s).trim()) { return true; // empty, ignore it } const [trivial, message] = external ? diff --git a/pattern_utils.js b/pattern_utils.js index ef1e304..7ab143b 100644 --- a/pattern_utils.js +++ b/pattern_utils.js @@ -31,10 +31,18 @@ exports.patternUtils = { removeNonalpha: function(str) { return str.replace(/[^a-z0-9<>@]+/gi, ''); }, + removeWhitespace: function(str) { return str.replace(/\/\//gmi, '').replace(/\*/gmi, '').replace(/\s+/gmi, ''); }, + replaceTokens: function(str) { return str.replace(/<.*?>/gi, '.*?'); + }, + + removeJsComments: function(str) { + const ml_comments = /\/\*.*?(\*\/)/g; + const il_comments = /\/\/.*/gm; + return str.replace(ml_comments, '').replace(il_comments, ''); } }; |