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

Merge pull request #2069 from PrivateBin/fix/qrCodeDisabled

 fix: fix exception when QR code is disabled in configuration
rugk 2 недель назад
Родитель
Сommit
7dcfff0a83
5 измененных файлов с 58 добавлено и 5 удалено
  1. 1 0
      .github/copilot-instructions.md
  2. 1 1
      CHANGELOG.md
  3. 9 3
      js/privatebin.js
  4. 46 0
      js/test/TopNav.js
  5. 1 1
      lib/Configuration.php

+ 1 - 0
.github/copilot-instructions.md

@@ -55,6 +55,7 @@
   - Always run after code changes to backend logic.
   - Always run after code changes to backend logic.
   - If `vendor/bin/phpunit` does not exist, ensure `composer install` completed without errors.
   - If `vendor/bin/phpunit` does not exist, ensure `composer install` completed without errors.
 
 
+- **JS Tests:**
   ```sh
   ```sh
   cd ./js
   cd ./js
   npm run test
   npm run test

+ 1 - 1
CHANGELOG.md

@@ -1,8 +1,8 @@
 # PrivateBin version history
 # PrivateBin version history
 
 
 ## 2.1.1 (not yet released)
 ## 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
 * ADDED: Translation for Korean (#2071)
 * ADDED: Translation for Korean (#2071)
-* FIXED: Creating a document failed with a JavaScript error when the `discussion` or `password` option is disabled, as the top navigation accessed the omitted elements
 * FIXED: Slovenian plural forms were stored in the wrong order, i.e. "1 uri" instead of "1 ura" for one hour (#1951)
 * 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)
 * 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)
 
 

+ 9 - 3
js/privatebin.js

@@ -4279,7 +4279,9 @@ window.PrivateBin = (function () {
             cloneButton.classList.remove('hidden');
             cloneButton.classList.remove('hidden');
             rawTextButton.classList.remove('hidden');
             rawTextButton.classList.remove('hidden');
             downloadTextButton.classList.remove('hidden');
             downloadTextButton.classList.remove('hidden');
-            qrCodeLink.classList.remove('hidden');
+            if (qrCodeLink) {
+                qrCodeLink.classList.remove('hidden');
+            }
 
 
             viewButtonsDisplayed = true;
             viewButtonsDisplayed = true;
         };
         };
@@ -4299,7 +4301,9 @@ window.PrivateBin = (function () {
             newButton.classList.add('hidden');
             newButton.classList.add('hidden');
             rawTextButton.classList.add('hidden');
             rawTextButton.classList.add('hidden');
             downloadTextButton.classList.add('hidden');
             downloadTextButton.classList.add('hidden');
-            qrCodeLink.classList.add('hidden');
+            if (qrCodeLink) {
+                qrCodeLink.classList.add('hidden');
+            }
             me.hideEmailButton();
             me.hideEmailButton();
 
 
             viewButtonsDisplayed = false;
             viewButtonsDisplayed = false;
@@ -4493,7 +4497,9 @@ window.PrivateBin = (function () {
          * @function
          * @function
          */
          */
         me.hideQrCodeButton = function () {
         me.hideQrCodeButton = function () {
-            qrCodeLink.classList.add('hidden');
+            if (qrCodeLink) {
+                qrCodeLink.classList.add('hidden');
+            }
         };
         };
 
 
         /**
         /**

+ 46 - 0
js/test/TopNav.js

@@ -10,11 +10,57 @@ function query(selector) {
 }
 }
 
 
 describe('TopNav', function () {
 describe('TopNav', function () {
+    describe('hideBurnAfterReadingButtons', function () {
+        it(
+            'hides buttons when the QR code button is disabled',
+            function () {
+                document.documentElement.innerHTML =
+                    '<nav><button id="clonebutton"></button></nav>';
+                PrivateBin.TopNav.init();
+
+                assert.doesNotThrow(function () {
+                    PrivateBin.TopNav.hideBurnAfterReadingButtons();
+                });
+                assert.ok(query('#clonebutton').classList.contains('hidden'));
+                cleanup();
+            }
+        );
+    });
+
     describe('showViewButtons & hideViewButtons', function () {
     describe('showViewButtons & hideViewButtons', function () {
         before(function () {
         before(function () {
             cleanup();
             cleanup();
         });
         });
 
 
+        it(
+            'shows and hides navigation elements when the QR code button is disabled',
+            function () {
+                document.documentElement.innerHTML =
+                    '<nav><button id="newbutton" class="hidden"></button>' +
+                    '<button id="clonebutton" class="hidden"></button>' +
+                    '<button id="rawtextbutton" class="hidden"></button>' +
+                    '<button id="downloadtextbutton" class="hidden"></button></nav>';
+                PrivateBin.TopNav.init();
+
+                assert.doesNotThrow(function () {
+                    PrivateBin.TopNav.showViewButtons();
+                });
+                assert.ok(!query('#newbutton').classList.contains('hidden'));
+                assert.ok(!query('#clonebutton').classList.contains('hidden'));
+                assert.ok(!query('#rawtextbutton').classList.contains('hidden'));
+                assert.ok(!query('#downloadtextbutton').classList.contains('hidden'));
+
+                assert.doesNotThrow(function () {
+                    PrivateBin.TopNav.hideViewButtons();
+                });
+                assert.ok(query('#newbutton').classList.contains('hidden'));
+                assert.ok(query('#clonebutton').classList.contains('hidden'));
+                assert.ok(query('#rawtextbutton').classList.contains('hidden'));
+                assert.ok(query('#downloadtextbutton').classList.contains('hidden'));
+                cleanup();
+            }
+        );
+
         it(
         it(
             'displays & hides navigation elements for viewing an existing document',
             'displays & hides navigation elements for viewing an existing document',
             function () {
             function () {

+ 1 - 1
lib/Configuration.php

@@ -124,7 +124,7 @@ class Configuration
             'js/kjua-0.10.0.js'      => 'sha512-BYj4xggowR7QD150VLSTRlzH62YPfhpIM+b/1EUEr7RQpdWAGKulxWnOvjFx1FUlba4m6ihpNYuQab51H6XlYg==',
             'js/kjua-0.10.0.js'      => 'sha512-BYj4xggowR7QD150VLSTRlzH62YPfhpIM+b/1EUEr7RQpdWAGKulxWnOvjFx1FUlba4m6ihpNYuQab51H6XlYg==',
             'js/legacy.js'           => 'sha512-pRofxsrf5UItjiP22Dcjh3FAcBjF/n7h8U9/W5xqJk17U0N2U1oajhXypq/omo9jhwS1iVGOhWrRepoPeFns+w==',
             'js/legacy.js'           => 'sha512-pRofxsrf5UItjiP22Dcjh3FAcBjF/n7h8U9/W5xqJk17U0N2U1oajhXypq/omo9jhwS1iVGOhWrRepoPeFns+w==',
             'js/prettify.js'         => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
             'js/prettify.js'         => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
-            'js/privatebin.js'       => 'sha512-RHO7+eilgNEa2UxlYWKx5lv6GB1oYBW15E7c/L/3QSDMhp2WVfjG5LOxF73atYxJgH1MwWO77IMe8iRtDeCbGg==',
+            'js/privatebin.js'       => 'sha512-R3QSK5EoeV/vdg3Gw0YqIKpkM8Da5+IOSXL4B1y8OdNJ7aMaY+TNlJaMP61/wF3oetOnczJB2FI3dAJ3IABWCA==',
             'js/purify-3.4.17.js'    => 'sha512-udF2zPdEyVCAxIGeBbeSGFK1Fj5c4eHGi6NqOSsr8M75lGs39POzgUNxO3SFxOg4cHfAoZJgR2EaXdmDi6v6AQ==',
             'js/purify-3.4.17.js'    => 'sha512-udF2zPdEyVCAxIGeBbeSGFK1Fj5c4eHGi6NqOSsr8M75lGs39POzgUNxO3SFxOg4cHfAoZJgR2EaXdmDi6v6AQ==',
             'js/showdown-2.1.0.js'   => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
             'js/showdown-2.1.0.js'   => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
             'js/zlib-1.3.2.js'       => 'sha512-RAhJgxg9siMIA8ky4c10Rc2zUgnK80olHB8Tt1IOYWY4Eh1WmrviQkDn+sgBlb38ZHq3tzufGC41kP360gmosQ==',
             'js/zlib-1.3.2.js'       => 'sha512-RAhJgxg9siMIA8ky4c10Rc2zUgnK80olHB8Tt1IOYWY4Eh1WmrviQkDn+sgBlb38ZHq3tzufGC41kP360gmosQ==',