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

added test for getCookie function, documenting its limitation of not finding cookies with empty identifier

El RIDO 9 лет назад
Родитель
Сommit
eedb05111a
4 измененных файлов с 30 добавлено и 3 удалено
  1. 1 1
      js/privatebin.js
  2. 27 0
      js/test.js
  3. 1 1
      tpl/bootstrap.php
  4. 1 1
      tpl/page.php

+ 1 - 1
js/privatebin.js

@@ -224,7 +224,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          * @see    {@link http://www.w3schools.com/js/js_cookies.asp}
          * @name   helper.getCookie
          * @function
-         * @param  {string} cname
+         * @param  {string} cname - may not be empty
          * @return {string}
          */
         getCookie: function(cname) {

+ 27 - 0
js/test.js

@@ -313,6 +313,33 @@ describe('helper', function () {
         );
     });
 
+    describe('getCookie', function () {
+        jsc.property(
+            'returns the requested cookie',
+            'nearray asciinestring',
+            'nearray asciistring',
+            function (labels, values) {
+                var selectedKey = '', selectedValue = '',
+                    cookieArray = [],
+                    count = 0;
+                labels.forEach(function(item, i) {
+                    var key = item.replace(/[\s;,=]/g, 'x'),
+                        value = (values[i] || values[0]).replace(/[\s;,=]/g, '');
+                    cookieArray.push(key + '=' + value);
+                    if (Math.random() < 1 / i)
+                    {
+                        selectedKey = key;
+                        selectedValue = value;
+                    }
+                });
+                var clean = jsdom('', {cookie: cookieArray}),
+                    result = $.PrivateBin.helper.getCookie(selectedKey);
+                clean();
+                return result === selectedValue;
+            }
+        );
+    });
+
     describe('scriptLocation', function () {
         jsc.property(
             'returns the URL without query & fragment',

+ 1 - 1
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bNqQCYlXhhJaoCspMQq5mmRFDsV5bXN1b+jr0N7zcG7Yd4hKXDYrSyxHrp1bavnpk1iG62o9rY4yTXHqarEZjw==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Ap3kgrXsOa+7xANzug/xGKb3rEOzCYuJoxUG5vmwYRWn/8wI9Cc/RYZehKnFwHuFCFnQzfqJ9GT2D1HSOdnd5g==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->

+ 1 - 1
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bNqQCYlXhhJaoCspMQq5mmRFDsV5bXN1b+jr0N7zcG7Yd4hKXDYrSyxHrp1bavnpk1iG62o9rY4yTXHqarEZjw==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Ap3kgrXsOa+7xANzug/xGKb3rEOzCYuJoxUG5vmwYRWn/8wI9Cc/RYZehKnFwHuFCFnQzfqJ9GT2D1HSOdnd5g==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->