Improved pattern for smiley code matches
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 09:34:12 +0000 (11:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 09:57:37 +0000 (11:57 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php

index d7d2b0372f7dec6bdeaf238154227798beece21a..c8f8593969ff95737c8c192560c52d9b3a874552 100644 (file)
@@ -415,17 +415,24 @@ class HtmlInputNodeTextParser {
        protected function parseSmiley(\DOMText $text, $value) {
                static $smileyPattern = null;
                if ($smileyPattern === null) {
+                       $difficultCodes = [];
                        foreach ($this->smilies as $smileyCode => $url) {
                                $smileyCode = preg_quote($smileyCode, '~');
                                
                                if (!preg_match('~^\\\:.+\\\:$~', $smileyCode)) {
-                                       $smileyCode = '\B' . $smileyCode . '\B';
+                                       $difficultCodes[] = $smileyCode;
+                                       continue;
                                }
                                
                                if (!empty($smileyPattern)) $smileyPattern .= '|';
                                $smileyPattern .= $smileyCode;
                        }
                        
+                       if (!empty($difficultCodes)) {
+                               if (!empty($smileyPattern)) $smileyPattern .= '|';
+                               $smileyPattern .= '(?<=\s|^)(?:' . implode('|', $difficultCodes) . ')(?=\s|$)';
+                       }
+                       
                        $smileyPattern = '~(' . $smileyPattern . ')~';
                }