fix: move config directives before definition finalization and use Mockery for CdnPurgeService stub
Some checks failed
CI / PHP 8.3 (push) Failing after 1m30s
CI / PHP 8.4 (push) Failing after 1m28s

- Move URI config calls before maybeGetRawHTMLDefinition() which
  finalizes the config and prevents further set() calls
- Use Mockery::mock()->shouldIgnoreMissing() for CdnPurgeService stub
  to satisfy type hint in ContentItemObserver

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude 2026-02-23 12:20:12 +00:00
parent ddf01c05b5
commit a332148056
No known key found for this signature in database
GPG key ID: AF404715446AEB41
2 changed files with 17 additions and 36 deletions

View file

@ -97,20 +97,6 @@ class HtmlSanitiser
$config->set('HTML.Nofollow', true);
$config->set('HTML.TargetNoopener', true);
// Disable cache and set definition ID for custom HTML definitions
$config->set('Cache.DefinitionImpl', null);
$config->set('HTML.DefinitionID', 'core-content-html5');
$config->set('HTML.DefinitionRev', 1);
// Register HTML5 elements that HTMLPurifier doesn't know about
if ($def = $config->maybeGetRawHTMLDefinition()) {
$def->addElement('section', 'Block', 'Flow', 'Common');
$def->addElement('article', 'Block', 'Flow', 'Common');
$def->addElement('figure', 'Block', 'Flow', 'Common');
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
$def->addElement('mark', 'Inline', 'Inline', 'Common');
}
// Safe URI schemes only
$config->set('URI.AllowedSchemes', [
'http' => true,
@ -123,6 +109,22 @@ class HtmlSanitiser
$config->set('URI.DisableExternalResources', false);
$config->set('URI.DisableResources', false);
// Disable cache and set definition ID for custom HTML definitions
$config->set('Cache.DefinitionImpl', null);
$config->set('HTML.DefinitionID', 'core-content-html5');
$config->set('HTML.DefinitionRev', 1);
// Register HTML5 elements that HTMLPurifier doesn't know about
// NOTE: maybeGetRawHTMLDefinition() finalizes the config — all
// $config->set() calls must come before this point.
if ($def = $config->maybeGetRawHTMLDefinition()) {
$def->addElement('section', 'Block', 'Flow', 'Common');
$def->addElement('article', 'Block', 'Flow', 'Common');
$def->addElement('figure', 'Block', 'Flow', 'Common');
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
$def->addElement('mark', 'Inline', 'Inline', 'Common');
}
$this->purifier = new HTMLPurifier($config);
}

View file

@ -30,28 +30,7 @@ abstract class TestCase extends BaseTestCase
// Stub external dependencies not available in test environment
if (! class_exists(\Plug\Cdn\CdnManager::class)) {
$app->bind(\Core\Mod\Content\Services\CdnPurgeService::class, fn () => new class
{
public function isEnabled(): bool
{
return false;
}
public function purgeContent($content)
{
return null;
}
public function purgeUrls(array $urls)
{
return null;
}
public function purgeWorkspace(string $uuid)
{
return null;
}
});
$app->bind(\Core\Mod\Content\Services\CdnPurgeService::class, fn () => \Mockery::mock(\Core\Mod\Content\Services\CdnPurgeService::class)->shouldIgnoreMissing());
}
}
}