diff --git a/js/privatebin.js b/js/privatebin.js index c990c359..6b16e7f8 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -566,10 +566,10 @@ jQuery.PrivateBin = (function($, RawDeflate) { // if $element is given, apply text to element if ($element !== null) { - // get last text node of element + // set the last text node of element let content = $element.contents(); if (content.length > 1) { - content[content.length - 1].nodeValue = ' ' + output; + $element.html(' ' + output).prepend(content[0]); } else { $element.text(output); } @@ -4803,11 +4803,21 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ function isOldBrowser() { // webcrypto support - if (typeof window.crypto !== 'object') { + if (!( + 'crypto' in window && + 'getRandomValues' in window.crypto && + 'subtle' in window.crypto && + 'encrypt' in window.crypto.subtle && + 'decrypt' in window.crypto.subtle && + 'Uint32Array' in window + )) { return true; } - if (typeof WebAssembly !== 'object' && typeof WebAssembly.instantiate !== 'function') { + if (!( + 'WebAssembly' in window && + 'instantiate' in window.WebAssembly + )) { return true; } try { diff --git a/js/test/Alert.js b/js/test/Alert.js index dfaf3535..9d009556 100644 --- a/js/test/Alert.js +++ b/js/test/Alert.js @@ -10,7 +10,7 @@ describe('Alert', function () { function (icon, message) { icon = icon.join(''); message = message.join(''); - var expected = ''; @@ -21,7 +21,7 @@ describe('Alert', function () { ); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.showStatus(message, icon); - var result = $('body').html(); + const result = $('body').html(); return expected === result; } ); @@ -39,7 +39,7 @@ describe('Alert', function () { function (icon, message) { icon = icon.join(''); message = message.join(''); - var expected = ''; @@ -50,7 +50,7 @@ describe('Alert', function () { ); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.showError(message, icon); - var result = $('body').html(); + const result = $('body').html(); return expected === result; } ); @@ -69,7 +69,7 @@ describe('Alert', function () { function (message, string, number) { message = message.join(''); string = string.join(''); - var expected = ''; @@ -80,7 +80,7 @@ describe('Alert', function () { ); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]); - var result = $('body').html(); + const result = $('body').html(); return expected === result; } ); @@ -98,7 +98,7 @@ describe('Alert', function () { function (message, icon) { message = message.join(''); icon = icon.join(''); - var defaultMessage = 'Loading…'; + const defaultMessage = 'Loading…'; if (message.length === 0) { message = defaultMessage; } @@ -114,7 +114,7 @@ describe('Alert', function () { ); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.showLoading(message, icon); - var result = $('body').html(); + const result = $('body').html(); return expected === result; } ); @@ -182,7 +182,7 @@ describe('Alert', function () { jsc.array(common.jscAlnumString()), function (trigger, message) { message = message.join(''); - var handlerCalled = false, + let handlerCalled = false, defaultMessage = 'Loading…', functions = [ $.PrivateBin.Alert.showStatus, diff --git a/js/test/InitialCheck.js b/js/test/InitialCheck.js index 5b0778cc..50c6dfb5 100644 --- a/js/test/InitialCheck.js +++ b/js/test/InitialCheck.js @@ -22,7 +22,6 @@ describe('InitialCheck', function () { '' ); $.PrivateBin.Alert.init(); - window.crypto = null; const result1 = !$.PrivateBin.InitialCheck.init(), result2 = !$('#errormessage').hasClass('hidden'); clean(); @@ -61,24 +60,19 @@ describe('InitialCheck', function () { jsc.property( 'shows error, if HTTP only site is detected', 'bool', - jsc.elements(['localhost', '127.0.0.1', '[::1]', '']), jsc.nearray(common.jscA2zString()), - jsc.elements(['.onion', '.i2p', '']), - function (secureProtocol, localhost, domain, tld) { - const isDomain = localhost === '', - isSecureContext = secureProtocol || !isDomain || tld.length > 0, - clean = jsdom('', { - 'url': (secureProtocol ? 'https' : 'http' ) + '://' + - (isDomain ? domain.join('') + tld : localhost) + '/' + function (secureProtocol, domain) { + const clean = jsdom('', { + 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/' }); $('body').html( ''+ '' ); $.PrivateBin.Alert.init(); - window.crypto = null; + window.crypto = new WebCrypto(); const result1 = $.PrivateBin.InitialCheck.init(), - result2 = isSecureContext === $('#httpnotice').hasClass('hidden'); + result2 = secureProtocol === $('#httpnotice').hasClass('hidden'); clean(); return result1 && result2; } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index caf4bb5f..07e86d96 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -71,7 +71,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 9b33be46..51f46612 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -49,7 +49,7 @@ if ($MARKDOWN): endif; ?> - +