diff --git a/src/ORM/Hierarchy/Hierarchy.php b/src/ORM/Hierarchy/Hierarchy.php
index c9eff0c8183..d92f3588c6d 100644
--- a/src/ORM/Hierarchy/Hierarchy.php
+++ b/src/ORM/Hierarchy/Hierarchy.php
@@ -808,8 +808,9 @@ public function getTreeTitle(): string
{
$owner = $this->getOwner();
$title = $owner->MenuTitle ?: $owner->Title;
+ $title = Convert::raw2xml($title ?? '');
$owner->extend('updateTreeTitle', $title);
- return Convert::raw2xml($title ?? '');
+ return $title;
}
/**
diff --git a/tests/php/ORM/HierarchyTest.php b/tests/php/ORM/HierarchyTest.php
index 4a367f5db3e..01a1f7f4e5a 100644
--- a/tests/php/ORM/HierarchyTest.php
+++ b/tests/php/ORM/HierarchyTest.php
@@ -9,6 +9,8 @@
use SilverStripe\Versioned\Versioned;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Hierarchy\Hierarchy;
+use SilverStripe\Security\Group;
+use SilverStripe\ORM\Tests\HierarchyTest\TestTreeTitleExtension;
class HierarchyTest extends SapphireTest
{
@@ -682,4 +684,15 @@ public function testDefaultParent(string $class, ?string $defaultParentConfig, ?
$this->assertSame($expected, $obj->defaultParent());
}
+
+ /**
+ * Tests that HTML added by an extension is not escaped, though HTML in the base Title still is
+ */
+ public function testGetTreeTitleExtension()
+ {
+ Group::add_extension(TestTreeTitleExtension::class);
+ $group = new Group();
+ $group->Title = 'My group';
+ $this->assertSame('<b>My group</b>', $group->getTreeTitle());
+ }
}
diff --git a/tests/php/ORM/HierarchyTest/TestTreeTitleExtension.php b/tests/php/ORM/HierarchyTest/TestTreeTitleExtension.php
new file mode 100644
index 00000000000..e8f72de82da
--- /dev/null
+++ b/tests/php/ORM/HierarchyTest/TestTreeTitleExtension.php
@@ -0,0 +1,14 @@
+$title";
+ }
+}