Skip to content

Commit

Permalink
FIX Apply raw2xml before extension hook
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 17, 2024
1 parent 4ca8dfd commit f03e59a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ORM/Hierarchy/Hierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/php/ORM/HierarchyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
*/
public function testGetTreeTitleExtension()
{
Group::add_extension(TestTreeTitleExtension::class);
$group = new Group();
$group->Title = 'My group';
$this->assertSame('<i>My group</i>', $group->getTreeTitle());
}
}
14 changes: 14 additions & 0 deletions tests/php/ORM/HierarchyTest/TestTreeTitleExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace SilverStripe\ORM\Tests\HierarchyTest;

use SilverStripe\Dev\TestOnly;
use SilverStripe\Core\Extension;

class TestTreeTitleExtension extends Extension implements TestOnly
{
protected function updateTreeTitle(string &$title)
{
$title = "<i>$title</i>";
}
}

0 comments on commit f03e59a

Please sign in to comment.