Просмотр исходного кода

fix: exception when email option was disabled in configuration

rugk 2 недель назад
Родитель
Сommit
24ba5b3ac4
3 измененных файлов с 31 добавлено и 1 удалено
  1. 1 1
      CHANGELOG.md
  2. 4 0
      js/privatebin.js
  3. 26 0
      js/test/TopNav.js

+ 1 - 1
CHANGELOG.md

@@ -1,7 +1,7 @@
 # PrivateBin version history
 
 ## 2.1.1 (not yet released)
-* FIXED: Creating a document failed with a JavaScript error when the `discussion`, `password` or QR code option is disabled, as the top navigation accessed the omitted elements
+* FIXED: Creating a document failed with a JavaScript error when the `discussion`, `password`, e-mail or QR code option is disabled, as the top navigation accessed the omitted elements
 * ADDED: Translation for Korean (#2071)
 * FIXED: Slovenian plural forms were stored in the wrong order, i.e. "1 uri" instead of "1 ura" for one hour (#1951)
 * FIXED: Lithuanian plural formula selected the "few" form for numbers ending in 0 above 10, i.e. "20 sekundės" instead of "20 sekundžių" (#1956)

+ 4 - 0
js/privatebin.js

@@ -4425,6 +4425,10 @@ window.PrivateBin = (function () {
          * @param {bool|undefined} optionalBurnAfterReading
          */
         me.showEmailButton = function (optionalRemainingTimeInSeconds, optionalBurnAfterReading) {
+            if (!emailLink) {
+                return;
+            }
+
             try {
                 // we cache expiration date in closure to avoid inaccurate expiration datetime
                 const expirationDate = Helper.calculateExpirationDate(

+ 26 - 0
js/test/TopNav.js

@@ -10,6 +10,32 @@ function query(selector) {
 }
 
 describe('TopNav', function () {
+    describe('showEmailButton', function () {
+        afterEach(function () {
+            cleanup();
+        });
+
+        it('does nothing when the email button is omitted from the page', function () {
+            document.documentElement.innerHTML =
+                '<nav><div id="navbar"><ul><li><button id="newbutton" ' +
+                'type="button">New</button></li></ul></div></nav>';
+            PrivateBin.TopNav.init();
+
+            const originalShowError = PrivateBin.Alert.showError;
+            let errorShown = false;
+            PrivateBin.Alert.showError = function () {
+                errorShown = true;
+            };
+
+            try {
+                assert.doesNotThrow(() => PrivateBin.TopNav.showEmailButton());
+                assert.strictEqual(errorShown, false);
+            } finally {
+                PrivateBin.Alert.showError = originalShowError;
+            }
+        });
+    });
+
     describe('hideBurnAfterReadingButtons', function () {
         it(
             'hides buttons when the QR code button is disabled',