Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

RegexpFilter.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.68 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\Items\AttributeFilters;
009   
010  use Exception;
011  use RuntimeException;
012  use s9e\TextFormatter\Configurator\Helpers\ContextSafeness;
013  use s9e\TextFormatter\Configurator\Helpers\RegexpParser;
014  use s9e\TextFormatter\Configurator\Items\AttributeFilter;
015  use s9e\TextFormatter\Configurator\Items\Regexp;
016   
017  class RegexpFilter extends AttributeFilter
018  {
019      /**
020      * Constructor
021      *
022      * @param  string $regexp PCRE regexp
023      */
024      public function __construct($regexp = null)
025      {
026          parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\RegexpFilter::filter');
027   
028          $this->resetParameters();
029          $this->addParameterByName('attrValue');
030          $this->addParameterByName('regexp');
031          $this->setJS('RegexpFilter.filter');
032   
033          if (isset($regexp))
034          {
035              $this->setRegexp($regexp);
036          }
037      }
038   
039      /**
040      * {@inheritdoc}
041      */
042      public function asConfig()
043      {
044          if (!isset($this->vars['regexp']))
045          {
046              throw new RuntimeException("Regexp filter is missing a 'regexp' value");
047          }
048   
049          return parent::asConfig();
050      }
051   
052      /**
053      * Return this filter's regexp
054      *
055      * @return string
056      */
057      public function getRegexp()
058      {
059          return (string) $this->vars['regexp'];
060      }
061   
062      /**
063      * Set this filter's regexp
064      *
065      * @param  string $regexp PCRE regexp
066      * @return void
067      */
068      public function setRegexp($regexp)
069      {
070          if (is_string($regexp))
071          {
072              $regexp = new Regexp($regexp);
073          }
074   
075          $this->vars['regexp'] = $regexp;
076          $this->resetSafeness();
077          $this->assessSafeness((string) $regexp);
078      }
079   
080      /**
081      * Assess the safeness of this attribute filter based on given regexp
082      *
083      * @param  string $filterRegexp
084      * @return void
085      */
086      protected function assessSafeness(string $filterRegexp): void
087      {
088          try
089          {
090              $regexp = RegexpParser::getAllowedCharacterRegexp($filterRegexp);
091          }
092          catch (Exception $e)
093          {
094              return;
095          }
096   
097          // Test whether this regexp could allow any character that's disallowed in each context
098          foreach (['AsURL', 'InCSS', 'InJS'] as $context)
099          {
100              $callback = ContextSafeness::class . '::getDisallowedCharacters' . $context;
101              foreach ($callback() as $char)
102              {
103                  if (preg_match($regexp, $char))
104                  {
105                      continue 2;
106                  }
107              }
108   
109              $methodName = 'markAsSafe' . $context;
110              $this->$methodName();
111          }
112   
113          // Regexps that start with a fixed scheme are considered safe as URLs unless the regexp is
114          // multiline. As a special case, we allow the scheme part to end with a single ? to allow
115          // the regexp "https?"
116          $regexp = '(^\\W\\^(?>\\((?:\\?:)?)*(?!data|\\w*script)\\w+\\??:.*\\W[a-ln-z]*+$)Dis';
117          if (preg_match($regexp, $filterRegexp))
118          {
119              $this->markAsSafeAsURL();
120          }
121      }
122  }