From c8bbdd3601aa871dc17adf495dfa0fa7294f63cb Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 31 Jan 2017 14:37:22 -0500 Subject: [PATCH 1/2] remove newline insertions from loop protect code --- dist/loop-protect.min.js | 4 ++-- lib/loop-protect.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/loop-protect.min.js b/dist/loop-protect.min.js index a9aae746..4278dff6 100644 --- a/dist/loop-protect.min.js +++ b/dist/loop-protect.min.js @@ -1,2 +1,2 @@ -/*! loop-protect | v1.0.1 | (c) 2016 Remy Sharp | http://jsbin.mit-license.org */ -!function(a,b){"use strict";"object"==typeof exports&&"object"==typeof module?module.exports=b(a):"function"==typeof define&&define.amd?define(b(a)):"object"==typeof exports?module.exports=b(a):a.loopProtect=b(a)}(this,function(a){"use strict";function b(a,b){if(0===a)return!1;var c=a,d=1,e=-1,f=-1;do{if(e=b[c].indexOf("*/"),f=b[c].indexOf("/*"),e!==-1&&d++,e===b[c].length-2&&f!==-1&&d--,f!==-1&&(d--,0===d))return!0;c-=1}while(c>=0);return!1}function c(a,b){for(var c;--a>-1;){if(c=b.substr(a,1),'"'===c||"'"===c||"."===c)return!0;if("/"===c||"*"===c){var d=b.substr(a-1,1);if("/"===d)return!0}}return!1}function d(a,b,c){h.lastIndex=0,i.lastIndex=0;var d=!1,e=c.slice(b).join("\n").substr(a).replace(i,"");return e.replace(h,function(a,b,c){var f=e.substr(0,c).replace(j,"").trim();0===f.length&&(d=!0)}),d}function e(a,e){function f(a,b,c){return b.slice(0,c)+"{;"+m+"({ line: "+a+", reset: true }); "+b.slice(c)}var h=[],j=a.split("\n"),l=!1,m=k.alias+".protect",n={},o={},p=null;return e||(e=0),j.forEach(function(a,k){if(g.lastIndex=0,i.lastIndex=0,!l){a.toLowerCase().indexOf("noprotect")!==-1&&(l=!0);var q=-1,r=-1,s=k,t=k-e+1,u="",v=!1,w=!1,x=!1,y=a.match(g)||[],z=y.length?y[0]:"",A=a.match(i)||[],B=0,C=0,D=!1;if(A.length&&(q=a.indexOf(A[1]),c(q,a)||b(k,j)||d(q,k,j)&&(p=k)),!n[k]){if(o[k])return void h.push(a);if(z&&1===y.length&&a.indexOf("jsbin")===-1){if(v="do"===z,r=q=a.indexOf(z),c(q,a))return void h.push(a);if(b(k,j))return void h.push(a);for(q=a.indexOf(z)+z.length,q===a.length&&q===a.length&&k=a.length&&(h.push(a),n[k]=!0,k++,a=j[k],q=0)}return}q++,q===a.length&&k500?(k.hit(a.line),!0):(b.last++,!1)},k.hit=function(b){var c="Exiting potential infinite loop at line "+b+'. To disable loop protection: add "// noprotect" to your code';a.proxyConsole?a.proxyConsole.error(c):console.error(c)},k.reset=function(){k.counters={}},k}); \ No newline at end of file +/*! loop-protect | v1.0.1 | (c) 2017 Remy Sharp | http://jsbin.mit-license.org */ +!function(a,b){"use strict";"object"==typeof exports&&"object"==typeof module?module.exports=b(a):"function"==typeof define&&define.amd?define(b(a)):"object"==typeof exports?module.exports=b(a):a.loopProtect=b(a)}(this,function(a){"use strict";function b(a,b){if(0===a)return!1;var c=a,d=1,e=-1,f=-1;do{if(e=b[c].indexOf("*/"),f=b[c].indexOf("/*"),e!==-1&&d++,e===b[c].length-2&&f!==-1&&d--,f!==-1&&(d--,0===d))return!0;c-=1}while(c>=0);return!1}function c(a,b){for(var c;--a>-1;){if(c=b.substr(a,1),'"'===c||"'"===c||"."===c)return!0;if("/"===c||"*"===c){var d=b.substr(a-1,1);if("/"===d)return!0}}return!1}function d(a,b,c){h.lastIndex=0,i.lastIndex=0;var d=!1,e=c.slice(b).substr(a).replace(i,"");return e.replace(h,function(a,b,c){var f=e.substr(0,c).replace(j,"").trim();0===f.length&&(d=!0)}),d}function e(a,e){function f(a,b,c){return b.slice(0,c)+"{;"+m+"({ line: "+a+", reset: true }); "+b.slice(c)}var h=[],j=a.split("\n"),l=!1,m=k.alias+".protect",n={},o={},p=null;return e||(e=0),j.forEach(function(a,k){if(g.lastIndex=0,i.lastIndex=0,!l){a.toLowerCase().indexOf("noprotect")!==-1&&(l=!0);var q=-1,r=-1,s=k,t=k-e+1,u="",v=!1,w=!1,x=!1,y=a.match(g)||[],z=y.length?y[0]:"",A=a.match(i)||[],B=0,C=0,D=!1;if(A.length&&(q=a.indexOf(A[1]),c(q,a)||b(k,j)||d(q,k,j)&&(p=k)),!n[k]){if(o[k])return void h.push(a);if(z&&1===y.length&&a.indexOf("jsbin")===-1){if(v="do"===z,r=q=a.indexOf(z),c(q,a))return void h.push(a);if(b(k,j))return void h.push(a);for(q=a.indexOf(z)+z.length,q===a.length&&q===a.length&&k=a.length&&(h.push(a),n[k]=!0,k++,a=j[k],q=0)}return}q++,q===a.length&&k500?(k.hit(a.line),!0):(b.last++,!1)},k.hit=function(b){var c="Exiting potential infinite loop at line "+b+'. To disable loop protection: add "// noprotect" to your code';a.proxyConsole?a.proxyConsole.error(c):console.error(c)},k.reset=function(){k.counters={}},k}); \ No newline at end of file diff --git a/lib/loop-protect.js b/lib/loop-protect.js index 4e98abb9..536d47b7 100644 --- a/lib/loop-protect.js +++ b/lib/loop-protect.js @@ -113,7 +113,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; } //jshint ignore:line labelRe.lastIndex = 0; var beforeLoop = false; - var theRest = lines.slice(lineNum).join('\n').substr(index).replace(labelRe, ''); + var theRest = lines.slice(lineNum).substr(index).replace(labelRe, ''); theRest.replace(reSingle, function commentStripper(match, capture, i) { var target = theRest.substr(0, i).replace(comments, '').trim(); DEBUG && debug('- directlyBeforeLoop: ' + target); // jshint ignore:line @@ -292,17 +292,17 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; } //jshint ignore:line if (lineNum !== originalLineNum) { DEBUG && debug('- multiline inline loop'); // jshint ignore:line // affect the compiled line - recompiled[originalLineNum] = recompiled[originalLineNum].substring(0, terminator + 1) + '{\nif (' + method + '({ line: ' + printLineNumber + ' })) break;\n' + recompiled[originalLineNum].substring(terminator + 1); - line += '\n}}\n'; + recompiled[originalLineNum] = recompiled[originalLineNum].substring(0, terminator + 1) + '{if (' + method + '({ line: ' + printLineNumber + ' })) break;' + recompiled[originalLineNum].substring(terminator + 1); + line += '}}'; } else { // simpler DEBUG && debug('- single line inline loop'); // jshint ignore:line - line = line.substring(0, terminator + 1) + '{\nif (' + method + '({ line: ' + printLineNumber + ' })) break;\n' + line.substring(terminator + 1) + '\n}}\n'; + line = line.substring(0, terminator + 1) + '{if (' + method + '({ line: ' + printLineNumber + ' })) break;' + line.substring(terminator + 1) + '}}'; } foundLoopEnd = true; } else if (character === '{') { DEBUG && debug('- multiline with braces'); // jshint ignore:line - var insert = ';\nif (' + method + '({ line: ' + printLineNumber + ' })) break;\n'; + var insert = ';if (' + method + '({ line: ' + printLineNumber + ' })) break;'; line = line.substring(0, index + 1) + insert + line.substring(index + 1); index += insert.length; From c9230037f45a41d96fd111911f30f28ff93b8090 Mon Sep 17 00:00:00 2001 From: gdamron Date: Wed, 1 Feb 2017 15:41:35 -0800 Subject: [PATCH 2/2] revert previous change to ensure subtr is applied to a string and not an array --- lib/loop-protect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loop-protect.js b/lib/loop-protect.js index 536d47b7..83a94e26 100644 --- a/lib/loop-protect.js +++ b/lib/loop-protect.js @@ -113,7 +113,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; } //jshint ignore:line labelRe.lastIndex = 0; var beforeLoop = false; - var theRest = lines.slice(lineNum).substr(index).replace(labelRe, ''); + var theRest = lines.slice(lineNum).join('\n').substr(index).replace(labelRe, ''); theRest.replace(reSingle, function commentStripper(match, capture, i) { var target = theRest.substr(0, i).replace(comments, '').trim(); DEBUG && debug('- directlyBeforeLoop: ' + target); // jshint ignore:line