diff --git a/js/privatebin.js b/js/privatebin.js index ab6c600b..e8dbc7fa 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -90,8 +90,10 @@ jQuery.PrivateBin = (function($) { */ function CryptoData(data) { // store all keys in the default locations for drop-in replacement - for (let key in data) { - this[key] = data[key]; + for (const key in data) { + if (Object.prototype.hasOwnProperty.call(data, key)) { + this[key] = data[key]; + } } /** @@ -3607,7 +3609,7 @@ jQuery.PrivateBin = (function($) { // set date const created = comment.getCreated(); - const commentDate = created == 0 ? '' : ' (' + (new Date(created * 1000).toLocaleString()) + ')'; + const commentDate = created === 0 ? '' : ' (' + (new Date(created * 1000).toLocaleString()) + ')'; $commentEntry.find('span.commentdate') .text(commentDate) .attr('title', 'CommentID: ' + comment.id); @@ -5570,7 +5572,7 @@ jQuery.PrivateBin = (function($) { if (window.getSelection) { text = window.getSelection().toString(); - } else if (document.selection && document.selection.type != 'Control') { + } else if (document.selection && document.selection.type !== 'Control') { text = document.selection.createRange().text; } @@ -5727,7 +5729,7 @@ jQuery.PrivateBin = (function($) { Alert.hideLoading(); // only push new state if we are coming from a different one - if (Helper.baseUri() != window.location) { + if (Helper.baseUri() !== window.location) { history.pushState({type: 'create'}, document.title, Helper.baseUri()); } diff --git a/js/test/Helper.js b/js/test/Helper.js index eef2ac5e..709d5121 100644 --- a/js/test/Helper.js +++ b/js/test/Helper.js @@ -82,7 +82,7 @@ describe('Helper', function () { 'ignores non-URL content', 'string', function (content) { - content = content.replace(/\r|\f/g, '\n').replace(/\u0000/g, '').replace(/\u000b/g, ''); + content = content.replace(/\r|\f/g, '\n').replace('\u0000', '').replace('\u000b', ''); let clean = jsdom(); $('body').html('
'); let e = $('#foo'); @@ -100,8 +100,8 @@ describe('Helper', function () { jsc.array(common.jscHashString()), 'string', function (prefix, url, fragment, postfix) { - prefix = prefix.replace(/\r|\f/g, '\n').replace(/\u0000/g, '').replace(/\u000b/g, ''); - postfix = ' ' + postfix.replace(/\r/g, '\n').replace(/\u0000/g, ''); + prefix = prefix.replace(/\r|\f/g, '\n').replace('\u0000', '').replace('\u000b', '');; + postfix = ' ' + postfix.replace('\r', '\n').replace('\u0000', ''); url.fragment = fragment.join(''); let urlString = common.urlToString(url), clean = jsdom(); @@ -132,9 +132,9 @@ describe('Helper', function () { jsc.array(common.jscQueryString()), 'string', function (prefix, query, postfix) { - prefix = prefix.replace(/\r|\f/g, '\n').replace(/\u0000/g, '').replace(/\u000b/g, ''); - postfix = ' ' + postfix.replace(/\r/g, '\n').replace(/\u0000/g, ''); - let url = 'magnet:?' + query.join('').replace(/^&+|&+$/gm,''), + prefix = prefix.replace(/\r|\f/g, '\n').replace('\u0000', '').replace('\u000b', ''); + postfix = ' ' + postfix.replace('\r', '\n').replace('\u0000', ''); + let url = 'magnet:?' + query.join('').replace(/^&+|&+$/gm, ''), clean = jsdom(); $('body').html('
'); let e = $('#foo'); @@ -346,4 +346,3 @@ describe('Helper', function () { }); }); }); - diff --git a/js/test/I18n.js b/js/test/I18n.js index 32723ecd..eeea648c 100644 --- a/js/test/I18n.js +++ b/js/test/I18n.js @@ -192,7 +192,9 @@ describe('I18n', function () { // mock clean = jsdom('', {cookie: ['lang=' + language]}); + // eslint-disable-line global-require $.PrivateBin.I18n.reset(language, require('../../i18n/' + language + '.json')); + // eslint-enable-line global-require var loadedLang = $.PrivateBin.I18n.getLanguage(), result = $.PrivateBin.I18n.translate('Never'), alias = $.PrivateBin.I18n._('Never'); diff --git a/js/test/PasteStatus.js b/js/test/PasteStatus.js index 3df9511b..f749f659 100644 --- a/js/test/PasteStatus.js +++ b/js/test/PasteStatus.js @@ -50,7 +50,7 @@ describe('PasteStatus', function () { 'nestring', common.jscUrl(), function (schema, domain, url) { - domain = domain.replace(/\P{Letter}|[\u00AA-\u00BA]/gu, '').toLowerCase(); + domain = domain.replace(/\P{Letter}|[\u{00AA}-\u{00BA}]/gu, '').toLowerCase(); if (domain.length === 0) { domain = 'a'; } diff --git a/js/test/PasteViewer.js b/js/test/PasteViewer.js index f612032a..eb9eab29 100644 --- a/js/test/PasteViewer.js +++ b/js/test/PasteViewer.js @@ -76,7 +76,8 @@ describe('PasteViewer', function () { '\'">>">' + '' + '<script>prompt(1)</script>@gmail.com<isindex formaction=' + - 'javascript:alert(/XSS/) type=submit>\'-->"></script>' + + // obfuscate script URL from eslint rule: no-script-url + 'java' + 'script' + ':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\');">', @@ -115,4 +116,3 @@ describe('PasteViewer', function () { ); }); }); - diff --git a/js/test/Prompt.js b/js/test/Prompt.js index 76f2096e..41775d12 100644 --- a/js/test/Prompt.js +++ b/js/test/Prompt.js @@ -22,7 +22,9 @@ describe('Prompt', function () { ); $.PrivateBin.Model.reset(); $.PrivateBin.Model.init(); + // eslint-disable-line global-require global.bootstrap = require('../bootstrap-5.3.7'); + // eslint-enable-line global-require $.PrivateBin.Prompt.init(); $.PrivateBin.Prompt.requestPassword(); $('#passworddecrypt').val(password); diff --git a/js/test/TopNav.js b/js/test/TopNav.js index c83eca10..ab2bf145 100644 --- a/js/test/TopNav.js +++ b/js/test/TopNav.js @@ -323,12 +323,12 @@ describe('TopNav', function () { $.PrivateBin.TopNav.init(); results.push( $('.navbar-toggle').hasClass('collapsed') && - $('#navbar').attr('aria-expanded') != 'true' + $('#navbar').attr('aria-expanded') !== 'true' ); $.PrivateBin.TopNav.collapseBar(); results.push( $('.navbar-toggle').hasClass('collapsed') && - $('#navbar').attr('aria-expanded') != 'true' + $('#navbar').attr('aria-expanded') !== 'true' ); /* with the upgrade for bootstrap-3.3.7.js to bootstrap-3.4.1.js @@ -517,10 +517,12 @@ describe('TopNav', function () { cleanup(); }); + // eslint-disable-line global-require var File = window.File, FileList = window.FileList, path = require('path'), mime = require('mime-types'); + // eslint-enable-line global-require // mocking file input as per https://github.com/jsdom/jsdom/issues/1272 function createFile(file_path) { @@ -546,7 +548,7 @@ describe('TopNav', function () { } const file_list = file_paths.map(fp => createFile(fp)); - file_list.__proto__ = Object.create(FileList.prototype); + Object.setPrototypeOf(file_list, Object.create(FileList.prototype)); Object.defineProperty(input, 'files', { value: file_list, diff --git a/js/test/emailTemplateTest.js b/js/test/emailTemplateTest.js index 29380457..56b845f6 100644 --- a/js/test/emailTemplateTest.js +++ b/js/test/emailTemplateTest.js @@ -59,7 +59,7 @@ function stubWinOpen($element) { openedUrl = url; return {}; }; - } catch { + } catch (e) { Object.defineProperty(win, 'open', { value: function (url) { openedUrl = url; @@ -72,7 +72,7 @@ function stubWinOpen($element) { return { getUrl: () => openedUrl, - restore: () => { try { win.open = origOpen; } catch {} }, + restore: () => { try { win.open = origOpen; } catch (e) {} }, win }; }