diff options
author | Nik Nyby <nikolas@gnu.org> | 2015-10-25 00:25:12 -0400 |
---|---|---|
committer | Nik Nyby <nikolas@gnu.org> | 2015-10-25 00:25:12 -0400 |
commit | 0321baba07850fa6cdecb0b5d683dfb631bf775b (patch) | |
tree | 86637916794fca924c94166f5157940d2fbc0bb2 | |
parent | deaf2b1d1233f9ac8cb6e16240b3619870728732 (diff) | |
download | librejsxul-0321baba07850fa6cdecb0b5d683dfb631bf775b.tar.lz librejsxul-0321baba07850fa6cdecb0b5d683dfb631bf775b.tar.xz librejsxul-0321baba07850fa6cdecb0b5d683dfb631bf775b.zip |
fix bug where @license-end could be ignored
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/js_checker/free_checker.js | 51 |
2 files changed, 36 insertions, 19 deletions
@@ -1,3 +1,7 @@ +2015-10-25 Nik Nyby <nikolas@gnu.org> + * Fixed a bug where @license-end was getting ignored + in some cases. Thanks to Micah Cowan for debugging this. + 2015-10-23 Nik Nyby <nikolas@gnu.org> * Converted LibreJS to use jpm instead of the old add-on system: cfx. Thanks to Adrian Aichner for helping out diff --git a/lib/js_checker/free_checker.js b/lib/js_checker/free_checker.js index be190e2..9da4b35 100644 --- a/lib/js_checker/free_checker.js +++ b/lib/js_checker/free_checker.js @@ -50,11 +50,10 @@ exports.freeCheck = { * */ stripLicenseToRegexp: function (license) { - var i = 0, - max = license.licenseFragments.length, - item; + var max = license.licenseFragments.length; + var item; - for (; i < max; i++) { + for (var i = 0; i < max; i++) { item = license.licenseFragments[i]; item.regex = patternUtils.removeNonalpha(item.text); @@ -95,10 +94,10 @@ exports.freeCheck = { isMagnetValid = false; if (n.counter === 2 && - n.parent != undefined && + typeof n.parent !== 'undefined' && n.parent.type === token.SCRIPT && - comment != undefined && - comment != " " + typeof comment !== 'undefined' && + comment !== " " ) { strippedComment = patternUtils.removeNonalpha(comment); matchLicStart = strippedComment.match(licStartLicEndRe); @@ -141,21 +140,34 @@ exports.freeCheck = { for (var license in list) { frag = list[license].canonicalUrl; console.debug("frag is ", frag); - if (frag != undefined) { + if (typeof frag !== 'undefined') { max = list[license].canonicalUrl.length; console.debug("max is", max); - for (i = 0;i < max; i++) { + for (var i = 0; i < max; i++) { console.debug("current frag is", frag[i]); if (frag[i].match(magnetLinkRe)) { - for (let i = 0; i < queue_end; i++) { - console.debug(queue[i]); - let n = queue[i]; + // The magnet link has a recognized license. + // Now just look for the @license-end. + for (var j = 0; j < queue.length; j++) { + let n = queue[j]; comment = this.getComment(n); - if (comment != undefined && + if (queue.length === 1 && + typeof comment === 'undefined' + ) { + // Didn't find a closing match, but + // there's only one node in the queue. + // Just accept this script. + return { + licenseName: list[license].licenseName, + type: types.checkTypes.FREE_SINGLE_ITEM + }; + } else if ( + typeof comment !== 'undefined' && comment.match(licenseEndMagnet) && this.checkIsLastNode(n) ) { - // found a closing match. Just accept this script. + // found a closing match. Just accept + // this script. return { licenseName: list[license].licenseName, type: types.checkTypes.FREE_SINGLE_ITEM @@ -167,7 +179,6 @@ exports.freeCheck = { } } } - return; }, /** @@ -181,13 +192,13 @@ exports.freeCheck = { */ checkIsLastNode: function (n) { // first check if the comment is part of the very last statement. - if (n.value == "this" && n.next == undefined) { + if (n.value === "this" && typeof n.next === 'undefined') { // just make sure the last node is indeed our harmless bit of // js. if (n.tokenizer) { let source = n.tokenizer.source; let substring = source.substr(n.start, n.end+23); - if (substring == END_OF_SCRIPT) { + if (substring === END_OF_SCRIPT) { return true; } else { @@ -213,7 +224,9 @@ exports.freeCheck = { getComment: function (n) { var i = 0, length, comment = ""; - if (n.blockComments == undefined || n.blockComments == " ") { + if (typeof n.blockComments === 'undefined' || + n.blockComments === " " + ) { return; } @@ -223,7 +236,7 @@ exports.freeCheck = { comment += n.blockComments[i]; } } - if (comment == "") { + if (comment === "") { return; } return comment; |