Improved the regex for simple embedded objects
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jun 2021 14:08:30 +0000 (16:08 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jun 2021 14:08:30 +0000 (16:08 +0200)
The previous version was borderline erroneous and while it worked so far, it could easily break in future versions of PHP.

wcfsetup/install/files/lib/system/html/simple/HtmlSimpleParser.class.php

index 497454bf57972f74f4a82faed7b108e85424dd1d..cc45be186d9b3ceb869e9e6ced089056618d868b 100644 (file)
@@ -35,7 +35,7 @@ class HtmlSimpleParser extends SingletonFactory
      * regex for simple placeholders
      * @var string
      */
-    protected $regexHandlers = '~{{\ ((?:[a-z][a-zA-Z]+="(?:\\"|[^"])+?"\ ?)*)\ }}~';
+    protected $regexHandlers = '~\{\{ ((?:[a-z][a-zA-Z]+="(?:\\\\"|[^"])+" ?)*) \}\}~';
 
     /**
      * @inheritDoc
@@ -77,7 +77,6 @@ class HtmlSimpleParser extends SingletonFactory
         foreach ($matches[1] as $attributesString) {
             $attributes = $this->parseAttributes($attributesString);
             $handler = $attributes['handler'];
-
             if (!isset($this->handlers[$handler])) {
                 // unknown handler, ignore
                 continue;
@@ -182,7 +181,7 @@ class HtmlSimpleParser extends SingletonFactory
      */
     protected function parseAttributes($attributesString)
     {
-        \preg_match_all('~([a-z][a-zA-Z]+)="((?:\\\\"|[^"])+?)"~', $attributesString, $attributes);
+        \preg_match_all('~([a-z][a-zA-Z]+)="((?:\\\\"|[^"])+)"~', $attributesString, $attributes);
 
         $additionalAttributes = [];
         for ($i = 1, $length = \count($attributes[0]); $i < $length; $i++) {