Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Apply raw2xml before extension hook #11517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, though HTML in the base Title still is
*/
public function testGetTreeTitleExtension()
{
Group::add_extension(TestTreeTitleExtension::class);
$group = new Group();
$group->Title = '<b>My group</b>';
$this->assertSame('<i>&lt;b&gt;My group&lt;/b&gt;</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>";
}
}
Loading