From e86693c682d15a29efd936c2b185e121a0c9ffda Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 29 Apr 2022 17:05:16 +1000 Subject: Stripping comments when checking between @license and @license-end example (say it's an external script): /* my awesome script */ /* @license magnet ... */ .... // @license-end --- main_background.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'main_background.js') 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 ? -- cgit v1.2.3