Fix the handling of mentions with and without leading `@`
authorAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2023 15:10:41 +0000 (17:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2023 15:10:41 +0000 (17:10 +0200)
com.woltlab.wcf/bbcode.xml
com.woltlab.wcf/templates/groupBBCodeTag.tpl
com.woltlab.wcf/templates/userBBCodeTag.tpl
wcfsetup/install/files/acp/templates/userBBCodeTag.tpl
wcfsetup/install/files/lib/system/bbcode/GroupBBCode.class.php
wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php

index 074a6322e05691d6d594d4b7015402abcaea31dc..5f84ea27a5f5273876e3c55f655bbc93015ab496 100644 (file)
                </bbcode>
                <bbcode name="user">
                        <classname>wcf\system\bbcode\UserBBCode</classname>
+                       <sourcecode>1</sourcecode>
                        <attributes>
                                <attribute name="0">
                                        <validationpattern><![CDATA[^\d+$]]></validationpattern>
                        </attributes>
                </bbcode>
                <bbcode name="group">
+                       <sourcecode>1</sourcecode>
                        <classname>wcf\system\bbcode\GroupBBCode</classname>
                        <attributes>
                                <attribute name="0">
index 74ae8bfc523a6030b315c1b63613dca7f6ea45ec..177ae1c612823ef7e53dc68f6571c5f9f1a78431 100644 (file)
@@ -1,5 +1,5 @@
 {if $group}
        <span class="groupMention">{$group->getName()}</span>
 {else}
-       @{$groupName}
+       {$groupName}
 {/if}
index dbe32b29d2a41c5719cef2f17a7ea824a4437370..369371df25c6c0a30c11e90226933546685116e4 100644 (file)
@@ -1,6 +1,6 @@
 {if $userProfile === null}
        {* user no longer exists, use plain output rather than using a broken link *}
-       @{$username}{* no newline after the tag
+       {$username}{* no newline after the tag
 *}{else}
        <a href="{link controller='User' object=$userProfile->getDecoratedObject()}{/link}" class="userMention userLink" data-object-id="{@$userProfile->userID}">{@$userProfile->getFormattedUsername()}</a>{* no newline after the tag
 *}{/if}
index dbe32b29d2a41c5719cef2f17a7ea824a4437370..369371df25c6c0a30c11e90226933546685116e4 100644 (file)
@@ -1,6 +1,6 @@
 {if $userProfile === null}
        {* user no longer exists, use plain output rather than using a broken link *}
-       @{$username}{* no newline after the tag
+       {$username}{* no newline after the tag
 *}{else}
        <a href="{link controller='User' object=$userProfile->getDecoratedObject()}{/link}" class="userMention userLink" data-object-id="{@$userProfile->userID}">{@$userProfile->getFormattedUsername()}</a>{* no newline after the tag
 *}{/if}
index 42160201b0cc617e623d661015bf99aa21fc6add..a58e949029a2838444477d37bf76f791d8f911c1 100644 (file)
@@ -20,10 +20,15 @@ final class GroupBBCode extends AbstractBBCode
      */
     public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser): string
     {
-        $groupID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0;
+        $content = $openingTag['attributes'][0];
+        if (!\str_starts_with($content, '@')) {
+            $content = "@{$content}";
+        }
+
+        $groupID = (!empty($openingTag['attributes'][1])) ? \intval($openingTag['attributes'][1]) : 0;
         $group = UserGroup::getGroupByID($groupID);
         if ($group === null || !$group->canBeMentioned()) {
-            return "[group]{$content}[/group]";
+            return $content;
         }
 
         return WCF::getTPL()->fetch('groupBBCodeTag', 'wcf', [
index d96c4b5d2e900e4201c7dced991c12587cd6756e..33d3c1c82eaa5b095b9cdaf533e9017a45c1f888 100644 (file)
@@ -21,9 +21,14 @@ final class UserBBCode extends AbstractBBCode
      */
     public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser): string
     {
-        $userID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0;
+        $content = $openingTag['attributes'][0];
+        if (!\str_starts_with($content, '@')) {
+            $content = "@{$content}";
+        }
+
+        $userID = (!empty($openingTag['attributes'][1])) ? \intval($openingTag['attributes'][1]) : 0;
         if (!$userID) {
-            return "[user]{$content}[/user]";
+            return $content;
         }
 
         /** @var UserProfile $userProfile */