From d2445f3d176f5d793eb7dab2baca34a1592bb4f7 Mon Sep 17 00:00:00 2001 From: jf-cbd Date: Fri, 14 Aug 2026 10:28:06 +0200 Subject: [PATCH] Rebase + adapt fix for 7385 --- application/utils.inc.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/application/utils.inc.php b/application/utils.inc.php index f21ab4780..8e769d17a 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -3036,24 +3036,36 @@ TXT public static function GetMentionedObjectsFromText(string $sText): array { $aMentionedObjects = []; + $aMentionAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes'); $oDom = new \DOMDocument(); libxml_use_internal_errors(true); // to keep processing even in case of "invalid" HTML, cf. testGetMentionedObjectsFromText - $oDom->loadHTML($sText); + $oDom->loadHTML(''.$sText); $oXpath = new \DOMXPath($oDom); $oNodes = $oXpath->query('//a[@data-object-class and @data-object-key]'); foreach ($oNodes as $oObjNode) { - $sObjClass = $oObjNode->getAttribute('data-object-class'); - $sObjId = $oObjNode->getAttribute('data-object-key'); + $sMatchedClass = $oObjNode->getAttribute('data-object-class'); + $sMatchedId = $oObjNode->getAttribute('data-object-key'); + $sMatchedName = trim($oObjNode->textContent); + + $sMentionPrefix = array_search($sMatchedClass, $aMentionAllowedClasses); // for N°7385 + if ($sMentionPrefix === false) { + continue; + } + + // Test if the visible mention starts with the expected configured marker. + if (str_starts_with($sMatchedName, $sMentionPrefix) === false) { + continue; + } // Prepare array for matched class if not already present - if (!array_key_exists($sObjClass, $aMentionedObjects)) { - $aMentionedObjects[$sObjClass] = []; + if (!array_key_exists($sMatchedClass, $aMentionedObjects)) { + $aMentionedObjects[$sMatchedClass] = []; } // Add matched ID if not already there - if (!in_array($sObjId, $aMentionedObjects[$sObjClass])) { - $aMentionedObjects[$sObjClass][] = $sObjId; + if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) { + $aMentionedObjects[$sMatchedClass][] = $sMatchedId; } }