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 30bb3d2
Show file tree
Hide file tree
Showing 3 changed files with 26 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
10 changes: 10 additions & 0 deletions tests/php/ORM/HierarchyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,14 @@ 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()
{
HierarchyTest\TestObject::add_extension(HierarchyTest\TestTreeTitleExtension::class);
$obj = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj1');
$this->assertSame('Obj 1', '<i>Obj 1</i>');
}
}
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)
{
return "<i>$title</i>";
}
}

0 comments on commit 30bb3d2

Please sign in to comment.