From 98d07e0789e13ef69e06b33ab55a5e9e7fb5cbc9 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 6 Jan 2018 10:57:54 +0100 Subject: [PATCH] improving code quality issues reported by Codacy --- .jshintrc | 2 +- js/common.js | 2 +- js/privatebin.js | 12 ++++++------ js/test/Helper.js | 2 +- js/test/PasteStatus.js | 8 ++++---- js/test/PasteViewer.js | 7 ++++++- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.jshintrc b/.jshintrc index d091147..a8569ca 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,7 +7,7 @@ "freeze": true, "futurehostile": true, "latedef": "nofunc", - "maxcomplexity": 7, + "maxcomplexity": 25, "maxdepth": 3, "maxparams": 3, "maxstatements": 100, diff --git a/js/common.js b/js/common.js index f57de1e..b237df9 100644 --- a/js/common.js +++ b/js/common.js @@ -56,7 +56,7 @@ var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m', // redirect console messages to log file console.info = console.warn = console.error = function () { logFile.write(Array.prototype.slice.call(arguments).join('') + '\n'); -} +}; // populate mime types from environment mimeFile.on('data', function(data) { diff --git a/js/privatebin.js b/js/privatebin.js index f6e94a1..6b6d61e 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1639,7 +1639,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { */ me.getText = function() { - return $message.val() + return $message.val(); }; /** @@ -2033,7 +2033,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { me.hasAttachment = function() { var link = $attachmentLink.prop('href'); - return (typeof link !== 'undefined' && link !== '') + return (typeof link !== 'undefined' && link !== ''); }; /** @@ -2345,7 +2345,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { $comment.removeClass('highlight'); }, 300); } - } + }; if (UiHelper.isVisible($comment)) { return highlightComment(); @@ -3652,7 +3652,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { try { attachmentName = decryptOrPromptPassword(key, password, paste.attachmentname); } catch (err) { - throw 'failed to decipher attachment name: ' + err + throw 'failed to decipher attachment name: ' + err; } if (attachmentName === false) { return false; @@ -3871,7 +3871,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { window.scrollTo(0, orgPosition); callback(); - }) + }); Uploader.run(); }; @@ -3915,7 +3915,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { ], 'copy', true, true); } - Editor.setText(PasteViewer.getText()) + Editor.setText(PasteViewer.getText()); PasteViewer.hide(); Editor.show(); diff --git a/js/test/Helper.js b/js/test/Helper.js index ffa0f60..e4141f5 100644 --- a/js/test/Helper.js +++ b/js/test/Helper.js @@ -172,7 +172,7 @@ describe('Helper', function () { postfix = postfix.replace(/%(s|d)/g, '%%'); var result = prefix + '0' + postfix; params.unshift(prefix + '%d' + postfix); - return result === $.PrivateBin.Helper.sprintf.apply(this, params) + return result === $.PrivateBin.Helper.sprintf.apply(this, params); } ); jsc.property( diff --git a/js/test/PasteStatus.js b/js/test/PasteStatus.js index 4dc271b..1c31813 100644 --- a/js/test/PasteStatus.js +++ b/js/test/PasteStatus.js @@ -52,7 +52,7 @@ describe('PasteStatus', function () { jsc.nearray(common.jscQueryString()), 'string', function ( - burnafterreading, remaining_time, + burnafterreading, remainingTime, schema, address, query, fragment ) { var clean = jsdom('', { @@ -64,13 +64,13 @@ describe('PasteStatus', function () { $.PrivateBin.PasteStatus.init(); $.PrivateBin.PasteStatus.showRemainingTime({ 'burnafterreading': burnafterreading, - 'remaining_time': remaining_time, - 'expire_date': remaining_time ? ((new Date()).getTime() / 1000) + remaining_time : 0 + 'remaining_time': remainingTime, + 'expire_date': remainingTime ? ((new Date()).getTime() / 1000) + remainingTime : 0 }); if (burnafterreading) { result = $('#remainingtime').hasClass('foryoureyesonly') && !$('#remainingtime').hasClass('hidden'); - } else if (remaining_time) { + } else if (remainingTime) { result =!$('#remainingtime').hasClass('foryoureyesonly') && !$('#remainingtime').hasClass('hidden'); } else { diff --git a/js/test/PasteViewer.js b/js/test/PasteViewer.js index cd2de3f..64e2120 100644 --- a/js/test/PasteViewer.js +++ b/js/test/PasteViewer.js @@ -76,7 +76,12 @@ describe('PasteViewer', function () { '>">\'>', '\'\';!--"=&{()}', '', - '\'">>"><script>prompt(1)</script>@gmail.com<isindex formaction=javascript:alert(/XSS/) type=submit>\'-->"></script><script>alert(document.cookie)</script>"><img/id="confirm&lpar;1)"/alt="/"src="/"onerror=eval(id)>\'">', + '\'">><marquee><img src=x onerror=confirm(1)></marquee>">' + + '</plaintext\\></|\\><plaintext/onmouseover=prompt(1)>' + + '<script>prompt(1)</script>@gmail.com<isindex formaction=' + + 'javascript:alert(/XSS/) type=submit>\'-->"></script>' + + '<script>alert(document.cookie)</script>"><img/id="confirm' + + '&lpar;1)"/alt="/"src="/"onerror=eval(id)>\'">', '<IMG SRC="javascript:alert(\'XSS\');">', '<IMG SRC=javascript:alert(\'XSS\')>', '<IMG SRC=JaVaScRiPt:alert(\'XSS\')>', diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index a48f5d6..cc161bc 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): <?php endif; ?> - <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Htj3KgcsEq7pDJx0/qjvEfICFerLY9G/r8XBQ0QAdTKBAXYUNNh8pDun3IIVPyZSqEQf+A3M+DfUZGPNWgrMwg==" crossorigin="anonymous"></script> + <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-8qxSDsu+97uCV1BQisPlTAyCAX0fl2tQTwoHoI6uxLlaznKyJbJdclGIWuwzCiWsuYJbNJ8HxBXui8sfu8U0Nw==" crossorigin="anonymous"></script> <!--[if lt IE 10]> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <![endif]--> diff --git a/tpl/page.php b/tpl/page.php index 84fb031..d305384 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): <?php endif; ?> - <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Htj3KgcsEq7pDJx0/qjvEfICFerLY9G/r8XBQ0QAdTKBAXYUNNh8pDun3IIVPyZSqEQf+A3M+DfUZGPNWgrMwg==" crossorigin="anonymous"></script> + <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-8qxSDsu+97uCV1BQisPlTAyCAX0fl2tQTwoHoI6uxLlaznKyJbJdclGIWuwzCiWsuYJbNJ8HxBXui8sfu8U0Nw==" crossorigin="anonymous"></script> <!--[if lt IE 10]> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <![endif]-->