From 692e7af19685c96031770aff4a9b0e11992842fc Mon Sep 17 00:00:00 2001 From: Ribas160 Date: Thu, 3 Jul 2025 13:13:42 +0300 Subject: [PATCH] - window.confirm fallbacks for page template removed - page template removed from configuration-test-generator --- bin/configuration-test-generator | 10 +-- js/privatebin.js | 119 +++++++++++-------------------- js/test/Prompt.js | 2 - lib/Configuration.php | 2 +- 4 files changed, 47 insertions(+), 86 deletions(-) diff --git a/bin/configuration-test-generator b/bin/configuration-test-generator index d81c3302..9b3de8f9 100755 --- a/bin/configuration-test-generator +++ b/bin/configuration-test-generator @@ -164,14 +164,14 @@ new ConfigurationTestGenerator(array( ), 'main/template' => array( array( - 'setting' => 'page', + 'setting' => 'bootstrap5', 'tests' => array( array( 'type' => 'MatchesRegularExpression', 'args' => array( - '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d[\d\.]+\d+"[^>]*/>#', + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap5/privatebin\.css\\?\d[\d\.]+\d+"[^>]*/>#', '$content', - 'outputs "page" stylesheet correctly', + 'outputs "bootstrap5" stylesheet correctly', ), ), array( 'type' => 'DoesNotMatchRegularExpression', @@ -189,9 +189,9 @@ new ConfigurationTestGenerator(array( array( 'type' => 'DoesNotMatchRegularExpression', 'args' => array( - '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d[\d\.]+\d+"[^>]*/>#', + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap5/privatebin\.css\\?\d[\d\.]+\d+"[^>]*/>#', '$content', - 'removes "page" stylesheet correctly', + 'removes "bootstrap5" stylesheet correctly', ), ), array( 'type' => 'MatchesRegularExpression', diff --git a/js/privatebin.js b/js/privatebin.js index 5448c67a..d0f5cb23 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2319,26 +2319,19 @@ jQuery.PrivateBin = (function($, RawDeflate) { me.requestLoadConfirmation = function() { const $loadconfirmmodal = $('#loadconfirmmodal'); - if ($loadconfirmmodal.length > 0) { - const $loadconfirmOpenNow = $loadconfirmmodal.find('#loadconfirm-open-now'); - $loadconfirmOpenNow.off('click.loadPaste'); - $loadconfirmOpenNow.on('click.loadPaste', PasteDecrypter.run); - const $loadconfirmClose = $loadconfirmmodal.find('.close'); - $loadconfirmClose.off('click.close'); - $loadconfirmClose.on('click.close', Controller.newPaste); - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($loadconfirmmodal[0])).show(); - } else { - $loadconfirmmodal.modal('show'); - } + + const $loadconfirmOpenNow = $loadconfirmmodal.find('#loadconfirm-open-now'); + $loadconfirmOpenNow.off('click.loadPaste'); + $loadconfirmOpenNow.on('click.loadPaste', PasteDecrypter.run); + + const $loadconfirmClose = $loadconfirmmodal.find('.close'); + $loadconfirmClose.off('click.close'); + $loadconfirmClose.on('click.close', Controller.newPaste); + + if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { + (new bootstrap.Modal($loadconfirmmodal[0])).show(); } else { - if (window.confirm( - I18n._('This secret message can only be displayed once. Would you like to see it now?') - )) { - PasteDecrypter.run(); - } else { - Controller.newPaste(); - } + $loadconfirmmodal.modal('show'); } } @@ -2360,15 +2353,6 @@ jQuery.PrivateBin = (function($, RawDeflate) { return; } - // fallback to old method for page template - password = prompt(I18n._('Please enter the password for this paste:'), ''); - if (password === null) { - throw 'password prompt canceled'; - } - if (password.length === 0) { - // recurse… - return me.requestPassword(); - } PasteDecrypter.run(); }; @@ -4193,59 +4177,42 @@ jQuery.PrivateBin = (function($, RawDeflate) { expirationDateRoundedToSecond.setUTCSeconds(0); const $emailconfirmmodal = $('#emailconfirmmodal'); - if ($emailconfirmmodal.length > 0) { - if (expirationDate !== null) { - const $emailconfirmTimezoneCurrent = $emailconfirmmodal.find('#emailconfirm-timezone-current'); - const $emailconfirmTimezoneUtc = $emailconfirmmodal.find('#emailconfirm-timezone-utc'); - let localeConfiguration = { dateStyle: 'long', timeStyle: 'long' }; - const bootstrap5EmailConfirmModal = typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION ? - new bootstrap.Modal($emailconfirmmodal[0]) : null; + if (expirationDate !== null) { + const $emailconfirmTimezoneCurrent = $emailconfirmmodal.find('#emailconfirm-timezone-current'); + const $emailconfirmTimezoneUtc = $emailconfirmmodal.find('#emailconfirm-timezone-utc'); + let localeConfiguration = { dateStyle: 'long', timeStyle: 'long' }; + const bootstrap5EmailConfirmModal = typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION ? + new bootstrap.Modal($emailconfirmmodal[0]) : null; - function sendEmailAndHideModal() { - const emailBody = templateEmailBody( - // we don't use Date.prototype.toUTCString() because we would like to avoid GMT - expirationDateRoundedToSecond.toLocaleString( - [], localeConfiguration - ), isBurnafterreading - ); - if (bootstrap5EmailConfirmModal) { - bootstrap5EmailConfirmModal.hide(); - } else { - $emailconfirmmodal.modal('hide'); - } - triggerEmailSend(emailBody); - }; - - $emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone'); - $emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', sendEmailAndHideModal); - $emailconfirmTimezoneUtc.off('click.sendEmailUtcTimezone'); - $emailconfirmTimezoneUtc.on('click.sendEmailUtcTimezone', () => { - localeConfiguration.timeZone = 'UTC'; - sendEmailAndHideModal(); - }); + function sendEmailAndHideModal() { + const emailBody = templateEmailBody( + // we don't use Date.prototype.toUTCString() because we would like to avoid GMT + expirationDateRoundedToSecond.toLocaleString( + [], localeConfiguration + ), isBurnafterreading + ); if (bootstrap5EmailConfirmModal) { - bootstrap5EmailConfirmModal.show(); + bootstrap5EmailConfirmModal.hide(); } else { - $emailconfirmmodal.modal('show'); + $emailconfirmmodal.modal('hide'); } + triggerEmailSend(emailBody); + }; + + $emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone'); + $emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', sendEmailAndHideModal); + $emailconfirmTimezoneUtc.off('click.sendEmailUtcTimezone'); + $emailconfirmTimezoneUtc.on('click.sendEmailUtcTimezone', () => { + localeConfiguration.timeZone = 'UTC'; + sendEmailAndHideModal(); + }); + if (bootstrap5EmailConfirmModal) { + bootstrap5EmailConfirmModal.show(); } else { - triggerEmailSend(templateEmailBody(null, isBurnafterreading)); + $emailconfirmmodal.modal('show'); } } else { - let emailBody = ''; - if (expirationDate !== null) { - const expirationDateString = window.confirm( - I18n._('Recipient may become aware of your timezone, convert time to UTC?') - ) ? expirationDateRoundedToSecond.toLocaleString( - undefined, - // we don't use Date.prototype.toUTCString() because we would like to avoid GMT - { timeZone: 'UTC', dateStyle: 'long', timeStyle: 'long' } - ) : expirationDateRoundedToSecond.toLocaleString(); - emailBody = templateEmailBody(expirationDateString, isBurnafterreading); - } else { - emailBody = templateEmailBody(null, isBurnafterreading); - } - triggerEmailSend(emailBody); + triggerEmailSend(templateEmailBody(null, isBurnafterreading)); } } @@ -4728,13 +4695,9 @@ jQuery.PrivateBin = (function($, RawDeflate) { // bootstrap template drop down $('#language ul.dropdown-menu li a').click(setLanguage); - // page template drop down - $('#language select').change(setLanguage); // bootstrap template drop down $('#template ul.dropdown-menu li a').click(setTemplate); - // page template drop down - $('#template select').change(setTemplate); // bind events $burnAfterReading.change(changeBurnAfterReading); diff --git a/js/test/Prompt.js b/js/test/Prompt.js index c854501c..afcb9866 100644 --- a/js/test/Prompt.js +++ b/js/test/Prompt.js @@ -2,8 +2,6 @@ require('../common'); describe('Prompt', function () { - // TODO: this does not test the prompt() fallback, since that isn't available - // in nodejs -> replace the prompt in the "page" template with a modal describe('requestPassword & getPassword', function () { this.timeout(30000); diff --git a/lib/Configuration.php b/lib/Configuration.php index a50a7fa3..31b2920a 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -118,7 +118,7 @@ class Configuration 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', - 'js/privatebin.js' => 'sha512-i0l0rh+NCY8Oeg9SxzQREHin6egXJ6sdIC84RTEsBpBNhYGObv8QEdRng1dMERZmw4olVeXx2ZCkusTyT1G+SA==', + 'js/privatebin.js' => 'sha512-lP3oQM8eZ6HNCUUZC2HvmNTO3RRNw7WPCCWbVVr0e9DHvgprYr6tYtDYzmWdpD6rzjHOgekHhFMO8LIO9ufyug==', 'js/purify-3.2.6.js' => 'sha512-zqwL4OoBLFx89QPewkz4Lz5CSA2ktU+f31fuECkF0iK3Id5qd3Zpq5dMby8KwHjIEpsUgOqwF58cnmcaNem0EA==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',