s9e / TextFormatter

Text formatting library that supports BBCode, HTML and other markup via plugins. Handles emoticons, censors words, automatically embeds media and more.
MIT License
232 stars 36 forks source link

2.15: TaskLists plugin broken #226

Closed tobyzerner closed 11 months ago

tobyzerner commented 11 months ago

Since upgrading to 2.15, TextFormatter is broken in Waterhole. Can be fixed by simply disabling the TaskList plugin (commenting out this line). Error and relevant stacktrace below.

[2023-12-07 08:47:42] local.ERROR: Not Found Error {"exception":"[object] (DOMException(code: 8): Not Found Error at /Users/toby/Sites/waterhole/vendor/s9e/sweetdom/src/NodeTraits/MagicMethods.php:44)
[stacktrace]
#0 /Users/toby/Sites/waterhole/vendor/s9e/sweetdom/src/NodeTraits/MagicMethods.php(44): DOMElement->replaceWith(Object(s9e\\SweetDOM\\Element))
#1 /Users/toby/Sites/waterhole/vendor/s9e/sweetdom/src/NodeTraits/PolyfillMethods.php(35): s9e\\SweetDOM\\Element->magicMethodsCall('replaceWithXslC...', Array)
#2 /Users/toby/Sites/waterhole/vendor/s9e/sweetdom/src/NodeTraits/DeprecatedMethods.php(48): s9e\\SweetDOM\\Element->polyfillMethodsCall('replaceWithXslC...', Array)
#3 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/DeoptimizeIf.php(27): s9e\\SweetDOM\\Element->__call('replaceWithXslC...', Array)
#4 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/AbstractNormalization.php(119): s9e\\TextFormatter\\Configurator\\TemplateNormalizations\\DeoptimizeIf->normalizeElement(Object(s9e\\SweetDOM\\Element))
#5 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/AbstractNormalization.php(48): s9e\\TextFormatter\\Configurator\\TemplateNormalizations\\AbstractNormalization->normalizeNode(Object(s9e\\SweetDOM\\Element))
#6 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizer.php(146): s9e\\TextFormatter\\Configurator\\TemplateNormalizations\\AbstractNormalization->normalize(Object(s9e\\SweetDOM\\Element))
#7 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/Items/Template.php(165): s9e\\TextFormatter\\Configurator\\TemplateNormalizer->normalizeTemplate('<input data-tas...')
#8 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizer.php(124): s9e\\TextFormatter\\Configurator\\Items\\Template->normalize(Object(s9e\\TextFormatter\\Configurator\\TemplateNormalizer))
#9 /Users/toby/Sites/waterhole/vendor/s9e/text-formatter/src/Configurator.php(239): s9e\\TextFormatter\\Configurator\\TemplateNormalizer->normalizeTag(Object(s9e\\TextFormatter\\Configurator\\Items\\Tag))
#10 /Users/toby/Sites/waterhole/packages/core/src/Formatter/Formatter.php(134): s9e\\TextFormatter\\Configurator->finalize()
JoshyPHP commented 11 months ago

Not Found errors are a bit scary because it might be a bug in ext/dom. Are you able to reproduce it with a minimal case, something like this for instance?

include '/path/to/vendor/autoload.php';

$config = new s9e\TextFormatter\Configurator;

$config->rootRules->enableAutoLineBreaks();
$config->urlConfig->allowScheme('mailto');
$config->urlConfig->allowScheme('upload');
$config->Escaper;
$config->Autoemail;
$config->Autolink;
$config->Litedown;
$config->PipeTables;
$config->TaskLists;
$config->Autovideo;
$config->Autoimage;

$config->finalize();

If so, what's your version of PHP?

tobyzerner commented 11 months ago

Ah, that's it. I reproduced on PHP 8.2.7 and 8.1.20. Upgraded to 8.2.13 and 8.1.26 and it seems to have been fixed. Thanks!

izdrail commented 11 months ago

so what's the fix ? Later edit: I've created a patch for now that just disable the task list once the fix will be applied i will remove that

JoshyPHP commented 11 months ago

Upgrade to a more recent version of PHP. I don't know the exact version number because I don't know which exact bug it hits but I think 8.2.9 and 8.1.21 or 8.1.22 should be fine. Or anything more recent including 8.3.0, obviously.