Properly passing bbcode's source for reversal
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 Jul 2016 14:28:09 +0000 (16:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 Jul 2016 14:28:34 +0000 (16:28 +0200)
wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php
wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php

index de926a6e54a1c0d9871c9f3904573e221898729a..c5b1ba57cccbc7f401c4c5a7081790fcc794cd63 100644 (file)
@@ -359,7 +359,7 @@ class HtmlBBCodeParser extends BBCodeParser {
                        $attributes = ' data-attributes="' . base64_encode(JSON::encode($tag['attributes'])) . '"';
                }
                
-               return '<woltlab-metacode-marker data-name="' . $name . '" data-uuid="' . $uuid . '"' . $attributes . ' />';
+               return '<woltlab-metacode-marker data-name="' . $name . '" data-uuid="' . $uuid . '" data-source="' . base64_encode($tag['source']) . '"' . $attributes . ' />';
        }
        
        /**
@@ -381,7 +381,7 @@ class HtmlBBCodeParser extends BBCodeParser {
                        return '';
                }
                
-               return '<woltlab-metacode-marker data-uuid="' . $data['uuid'] . '" />';
+               return '<woltlab-metacode-marker data-uuid="' . $data['uuid'] . '" data-source="' . base64_encode($tag['source']) . '" />';
        }
        
        /**
index 0ef1557801035c55d5be4c1b382b94a9ddc47ad2..11a3efacd95b9b4792f726927034fa751ee3fbda 100644 (file)
@@ -88,6 +88,7 @@ class MessageHtmlInputFilter implements IHtmlInputFilter {
                $definition->addElement('woltlab-metacode-marker', 'Inline', 'Empty', '', [
                        'data-attributes' => 'Text',
                        'data-name' => 'Text',
+                       'data-source' => 'Text',
                        'data-uuid' => 'Text'
                ]);
                
index fd01b195308385edb52d316c701a9095e53acc32..d8577a335ccfb82e4e029a1d1f640021bf144052 100644 (file)
@@ -129,6 +129,7 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
                        $attributes = $element->getAttribute('data-attributes');
                        $name = $element->getAttribute('data-name');
                        $uuid = $element->getAttribute('data-uuid');
+                       $source = @base64_decode($element->getAttribute('data-source'));
                        
                        if (!isset($pairs[$uuid])) {
                                $pairs[$uuid] = [
@@ -143,9 +144,11 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
                                $pairs[$uuid]['attributes'] = $attributes;
                                $pairs[$uuid]['name'] = $name;
                                $pairs[$uuid]['open'] = $element;
+                               $pairs[$uuid]['openSource'] = $source;
                        }
                        else {
                                $pairs[$uuid]['close'] = $element;
+                               $pairs[$uuid]['closeSource'] = $source;
                        }
                }
                
@@ -194,7 +197,9 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
                        $groups[$name][] = [
                                'attributes' => $data['attributes'],
                                'close' => $data['close'],
-                               'open' => $data['open']
+                               'closeSource' => $data['closeSource'],
+                               'open' => $data['open'],
+                               'openSource' => $data['openSource']
                        ];
                }
                
@@ -430,11 +435,11 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
                $end = $pair['close'];
                
                $attributes = (isset($pair['attributes'])) ? $pair['attributes'] : '';
-               $textNode = $start->ownerDocument->createTextNode(HtmlBBCodeParser::getInstance()->buildBBCodeTag($name, $attributes, true));
+               $textNode = $start->ownerDocument->createTextNode(($pair['openSource']) ?: HtmlBBCodeParser::getInstance()->buildBBCodeTag($name, $attributes, true));
                DOMUtil::insertBefore($textNode, $start);
                DOMUtil::removeNode($start);
                
-               $textNode = $end->ownerDocument->createTextNode('[/' . $name . ']');
+               $textNode = $end->ownerDocument->createTextNode(($pair['closeSource']) ?: '[/' . $name . ']');
                DOMUtil::insertBefore($textNode, $end);
                DOMUtil::removeNode($end);
        }