Fixed code bbcodes evaluated inside code HTML tags
authorAlexander Ebert <ebert@woltlab.com>
Mon, 26 Sep 2016 14:54:41 +0000 (16:54 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 26 Sep 2016 14:54:47 +0000 (16:54 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php

index 575a6860d0c1d64bbaacfa39d61aa2f35b24782b..6e3468c97d2d8283233cb904dd13b0c4fa8b4c8c 100644 (file)
@@ -79,30 +79,11 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
         * @return      array                           filtered groups without source bbcodes
         */
        protected function revertMarkerInsideCodeBlocks(array $groups, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
-               $isInsideCode = function(\DOMElement $element) {
-                       $parent = $element;
-                       while ($parent = $parent->parentNode) {
-                               $nodeName = $parent->nodeName;
-                               
-                               if ($nodeName === 'code' || $nodeName === 'kbd' || $nodeName === 'pre') {
-                                       return true;
-                               }
-                               else if ($nodeName === 'woltlab-metacode') {
-                                       $name = $parent->getAttribute('data-name');
-                                       if ($name === 'code' || $name === 'tt') {
-                                               return true;
-                                       }
-                               }
-                       }
-                       
-                       return false;
-               };
-               
                foreach ($groups as $name => $pairs) {
                        $needsReindex = false;
                        for ($i = 0, $length = count($pairs); $i < $length; $i++) {
                                $pair = $pairs[$i];
-                               if ($isInsideCode($pair['open']) || $isInsideCode($pair['close'])) {
+                               if ($this->isInsideCode($pair['open']) || $this->isInsideCode($pair['close'])) {
                                        $pair['attributes'] = $htmlNodeProcessor->parseAttributes($pair['attributes']);
                                        $this->convertToBBCode($name, $pair);
                                        
@@ -124,6 +105,25 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
                return $groups;
        }
        
+       protected function isInsideCode(\DOMElement $element) {
+               $parent = $element;
+               while ($parent = $parent->parentNode) {
+                       $nodeName = $parent->nodeName;
+                       
+                       if ($nodeName === 'code' || $nodeName === 'kbd' || $nodeName === 'pre') {
+                               return true;
+                       }
+                       else if ($nodeName === 'woltlab-metacode') {
+                               $name = $parent->getAttribute('data-name');
+                               if ($name === 'code' || $name === 'tt') {
+                                       return true;
+                               }
+                       }
+               }
+               
+               return false;
+       }
+       
        /**
         * Builds the list of paired bbcode markers.
         * 
@@ -222,25 +222,31 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
         */
        protected function convertSourceGroups(array $groups) {
                foreach ($this->sourceElements as $name) {
-                       if (in_array($name, $this->blockElements)) {
-                               if (isset($groups[$name])) {
-                                       for ($i = 0, $length = count($groups[$name]); $i < $length; $i++) {
-                                               $data = $groups[$name][$i];
-                                               $this->convertBlockElement($name, $data['open'], $data['close'], $data['attributes']);
-                                       }
-                                       
-                                       unset($groups[$name]);
+                       if (!isset($groups[$name])) {
+                               continue;
+                       }
+                       
+                       for ($i = 0, $length = count($groups[$name]); $i < $length; $i++) {
+                               $data = $groups[$name][$i];
+                               if ($this->isInsideCode($data['open']) || $this->isInsideCode($data['close'])) {
+                                       continue;
                                }
+                               
+                               if (in_array($name, $this->blockElements)) {
+                                       $this->convertBlockElement($name, $data['open'], $data['close'], $data['attributes']);
+                               }
+                               else {
+                                       $this->convertInlineElement($name, $data['open'], $data['close'], $data['attributes']);
+                               }
+                               
+                               unset($groups[$name][$i]);
+                       }
+                       
+                       if (empty($groups[$name])) {
+                               unset($groups[$name]);
                        }
                        else {
-                               if (isset($groups[$name])) {
-                                       for ($i = 0, $length = count($groups[$name]); $i < $length; $i++) {
-                                               $data = $groups[$name][$i];
-                                               $this->convertInlineElement($name, $data['open'], $data['close'], $data['attributes']);
-                                       }
-                                       
-                                       unset($groups[$name]);
-                               }
+                               $groups[$name] = array_values($groups[$name]);
                        }
                }