From ef338f7693fe5339d833679aed1c7e7e399b67f2 Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Mon, 26 Mar 2018 12:05:50 -0500 Subject: Fixed failed license recognition bug for script declarations with magnet links --- legacy_license_check.js | 16 ++++++---------- main_background.js | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/legacy_license_check.js b/legacy_license_check.js index dc3458a..00d341e 100644 --- a/legacy_license_check.js +++ b/legacy_license_check.js @@ -49,11 +49,10 @@ var license_regexes = []; var init = function(){ console.log("initializing regexes"); - for (var item in data.licenses) { license_regexes.push(stripLicenseToRegexp(data.licenses[item])); } - console.log(license_regexes); + //console.log(license_regexes); } module.exports.init = init; @@ -67,8 +66,8 @@ var search_table = function(stripped_comment){ var stripped = match_utils.removeNonalpha(stripped_comment); //stripped = stripped.replaceTokens(stripped_comment); - console.log("Looking up license"); - console.log(stripped); + //console.log("Looking up license"); + //console.log(stripped); for (license in data.licenses) { frag = data.licenses[license].licenseFragments; @@ -90,11 +89,11 @@ var search_table = function(stripped_comment){ * returns true for "free" and false for anything else */ var check = function(license_text){ - console.log("checking..."); - console.log(license_text); + //console.log("checking..."); + //console.log(license_text); if(license_text === undefined || license_text === null || license_text == ""){ - console.log("Was not an inline script"); + //console.log("Was not an inline script"); return false; } // remove whitespace @@ -106,9 +105,6 @@ var check = function(license_text){ return false; } var declaration = matches[0]; - - console.log("Got to this point"); - console.log(declaration); return search_table(declaration); diff --git a/main_background.js b/main_background.js index 30ed411..b159ff1 100644 --- a/main_background.js +++ b/main_background.js @@ -663,6 +663,8 @@ function full_evaluate(script){ try{ var toke = tokens.getToken(); }catch(e){ + console.log(script); + console.log(e); console.warn("couldn't get first token (probably invalid code)"); console.warn("Continuing evaluation"); } @@ -815,9 +817,9 @@ function evaluate(script,name){ return [flag,reason+"
"]; } - var temp = full_evaluate(temp); - temp[1] = temp[1] + "
"; - return temp; + var final = full_evaluate(temp); + final[1] = final[1] + "
"; + return final; } @@ -859,7 +861,7 @@ function license_read(script_src, name){ var parts_accepted = false; while(true){ // TODO: refactor me // TODO: support multiline comments - var matches = /\/\s*?(@license)\s([\S]+)\s([\S]+$)/gm.exec(unedited_src); + var matches = /\/\/\s*?(@license)\s([\S]+)\s([\S]+$)/gm.exec(unedited_src); if(matches == null){ nontrivial_status = evaluate(unedited_src,name); if(nontrivial_status[0] == true){ @@ -880,7 +882,15 @@ function license_read(script_src, name){ else return [true,edited_src,reason_text]; } - var before = unedited_src.substr(0,matches["index"]); + // sponge + console.log("undedited_src:"); + console.log(unedited_src); + console.log(matches); + console.log("chopping at " + matches["index"] + "."); + var before = unedited_src.substring(0,matches["index"]); + // sponge + console.log("before:"); + console.log(before); nontrivial_status = evaluate(before,name); if(nontrivial_status[0] == true){ parts_accepted = true; -- cgit v1.2.3