[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Parser/AttributeFilters/ -> NetworkFilter.js (source)

   1  /** @const */
   2  var NetworkFilter =
   3  {
   4      /**
   5      * @param  {*} attrValue
   6      * @return {*}
   7      */
   8      filterIp: function(attrValue)
   9      {
  10          if (/^[\d.]+$/.test(attrValue))
  11          {
  12              return NetworkFilter.filterIpv4(attrValue);
  13          }
  14  
  15          if (/^[\da-f:]+$/i.test(attrValue))
  16          {
  17              return NetworkFilter.filterIpv6(attrValue);
  18          }
  19  
  20          return false;
  21      },
  22  
  23      /**
  24      * @param  {*} attrValue
  25      * @return {*}
  26      */
  27      filterIpport: function(attrValue)
  28      {
  29          var m, ip;
  30  
  31          if (m = /^\[([\da-f:]+)(\]:[1-9]\d*)$/i.exec(attrValue))
  32          {
  33              ip = NetworkFilter.filterIpv6(m[1]);
  34  
  35              if (ip === false)
  36              {
  37                  return false;
  38              }
  39  
  40              return '[' + ip + m[2];
  41          }
  42  
  43          if (m = /^([\d.]+)(:[1-9]\d*)$/.exec(attrValue))
  44          {
  45              ip = NetworkFilter.filterIpv4(m[1]);
  46  
  47              if (ip === false)
  48              {
  49                  return false;
  50              }
  51  
  52              return ip + m[2];
  53          }
  54  
  55          return false;
  56      },
  57  
  58      /**
  59      * @param  {*} attrValue
  60      * @return {*}
  61      */
  62      filterIpv4: function(attrValue)
  63      {
  64          if (!/^\d+\.\d+\.\d+\.\d+$/.test(attrValue))
  65          {
  66              return false;
  67          }
  68  
  69          var i = 4, p = attrValue.split('.');
  70          while (--i >= 0)
  71          {
  72              // NOTE: ext/filter doesn't support octal notation
  73              if (p[i][0] === '0' || p[i] > 255)
  74              {
  75                  return false;
  76              }
  77          }
  78  
  79          return attrValue;
  80      },
  81  
  82      /**
  83      * @param  {*} attrValue
  84      * @return {*}
  85      */
  86      filterIpv6: function(attrValue)
  87      {
  88          return /^([\da-f]{0,4}:){2,7}(?:[\da-f]{0,4}|\d+\.\d+\.\d+\.\d+)$/.test(attrValue) ? attrValue : false;
  89      }
  90  };


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1