Improved encoding of emails
authorMarcel Werk <burntime@woltlab.com>
Sun, 21 Sep 2014 18:38:06 +0000 (20:38 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 21 Sep 2014 18:38:06 +0000 (20:38 +0200)
Closes #1566

com.woltlab.wcf/bbcode.xml
wcfsetup/install/files/lib/system/bbcode/EmailBBCode.class.php [new file with mode: 0644]

index 5d889f89ce6c50b22dd73e19ffd6e02889fbfa34..173cb543bbe37ff3df1cbc1e063d9b61f12d7bc8 100644 (file)
                        <allowedchildren>all^sup</allowedchildren>
                </bbcode>
                <bbcode name="email">
-                       <htmlopen>a</htmlopen>
-                       <htmlclose>a</htmlclose>
+                       <classname><![CDATA[wcf\system\bbcode\EmailBBCode]]></classname>
                        <allowedchildren>none^img,b,i,u,s,sub,sup,color,size,font</allowedchildren>
                        <attributes>
                                <attribute name="0">
-                                       <html>href="mailto:%s"</html>
                                        <required>1</required>
                                        <usetext>1</usetext>
                                        <validationpattern>^[^\s]+@[^\s]+$</validationpattern>
diff --git a/wcfsetup/install/files/lib/system/bbcode/EmailBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/EmailBBCode.class.php
new file mode 100644 (file)
index 0000000..80c13cb
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace wcf\system\bbcode;
+use wcf\util\StringUtil;
+
+/**
+ * Parses the [email] bbcode tag.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.bbcode
+ * @category   Community Framework
+ */
+class EmailBBCode extends AbstractBBCode {
+       /**
+        * @see \wcf\system\bbcode\IBBCode::getParsedTag()
+        */
+       public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) {
+               $email = '';
+               if (isset($openingTag['attributes'][0])) {
+                       $email = $openingTag['attributes'][0];
+               }
+               $email = StringUtil::decodeHTML($email);
+               
+               return '<a href="mailto:' . StringUtil::encodeAllChars($email) . '">' . $content . '</a>';
+       }
+}