Empty body field partly breaks Typogrify for other fields

Created on 29 January 2024, 5 months ago
Updated 30 January 2024, 5 months ago

Steps to reproduce

I have a page where I set up a text format with Typogrify as a filter, and other fields use Typogrify as well (directly in the twig template, i.e. {{ fields.title.content|typogrify }}).

If I leave the body field empty, Typogrify seems to be partly broken on all other fields on the page. For instance, I can see that the span tag for caps is added where needed, but Typogrify's CSS file is not loaded, and the caps simply look the same as regular text (<link rel="stylesheet" media="all" href="/modules/contrib/typogrify/assets/typogrify.css" /> is simply missing in the page's source code).

The logs show the following error message:

Deprecated function: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\typogrify\Typogrify::amp() (line 28 of [Drupal root]/modules/contrib/typogrify/src/Typogrify.php)

#0 [Drupal root]/core/includes/bootstrap.inc(158): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 [Drupal root]/modules/contrib/typogrify/src/Typogrify.php(28): preg_replace()
#3 [Drupal root]/modules/contrib/typogrify/src/Typogrify.php(216): Drupal\typogrify\Typogrify::amp()
#4 [Drupal root]/modules/contrib/typogrify/src/TwigExtension/Typogrify.php(45): Drupal\typogrify\Typogrify::filter()
#5 [Drupal root]/vendor/twig/twig/src/Environment.php(361) : eval()'d code(64): Drupal\typogrify\TwigExtension\Typogrify::filter()
#6 [Drupal root]/vendor/twig/twig/src/Template.php(394): __TwigTemplate_092b59c4990c8e6f18585e867f3c7e06->doDisplay()
#7 [Drupal root]/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling()
#8 [Drupal root]/vendor/twig/twig/src/Template.php(379): Twig\Template->display()
#9 [Drupal root]/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render()
#10 [Drupal root]/core/themes/engines/twig/twig.engine(53): Twig\TemplateWrapper->render()
#11 [Drupal root]/core/lib/Drupal/Core/Theme/ThemeManager.php(372): twig_render_template()
#12 [Drupal root]/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
#13 [Drupal root]/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#14 [Drupal root]/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(158): Drupal\Core\Render\Renderer->render()
#15 [Drupal root]/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#16 [Drupal root]/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(159): Drupal\Core\Render\Renderer->executeInRenderContext()
#17 [Drupal root]/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#18 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#19 [Drupal root]/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#20 [Drupal root]/vendor/symfony/http-kernel/HttpKernel.php(168): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#21 [Drupal root]/vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#22 [Drupal root]/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#23 [Drupal root]/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#24 [Drupal root]/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#25 [Drupal root]/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#26 [Drupal root]/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle()
#27 [Drupal root]/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle()
#28 [Drupal root]/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#29 [Drupal root]/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#30 [Drupal root]/core/lib/Drupal/Core/DrupalKernel.php(686): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#31 [Drupal root]/index.php(19): Drupal\Core\DrupalKernel->handle()
#32 {main}

Tested with Drupal 10.2.2 and Typogrify 8x-1.3 on PHP 8.1.

🐛 Bug report
Status

Active

Version

1.3

Component

Code

Created by

🇨🇭Switzerland maenjuel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @maenjuel
  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • 🇮🇳India abhishek_virasat

    @maenjuel, fixed the issue and created Patch , please review patch file

  • Status changed to Active 5 months ago
  • 🇨🇭Switzerland maenjuel

    Thank you for looking into the issue @abhishek_gupta1

    The outcome is still the same, but now with a slightly different error message:

    Deprecated function: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\typogrify\Typogrify::widont() (line 203 of [Drupal root]/web/modules/contrib/typogrify/src/Typogrify.php)
    
    #0 [Drupal root]/web/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
    #1 [internal function]: _drupal_error_handler()
    #2 [Drupal root]/web/modules/contrib/typogrify/src/Typogrify.php(203): preg_replace()
    #3 [Drupal root]/web/modules/contrib/typogrify/src/Typogrify.php(224): Drupal\typogrify\Typogrify::widont()
    #4 [Drupal root]/web/modules/contrib/typogrify/src/TwigExtension/Typogrify.php(45): Drupal\typogrify\Typogrify::filter()
    #5 [Drupal root]/vendor/twig/twig/src/Environment.php(360) : eval()'d code(64): Drupal\typogrify\TwigExtension\Typogrify::filter()
    #6 [Drupal root]/vendor/twig/twig/src/Template.php(394): __TwigTemplate_eb27fdd977272c00be557825c92b6f9b->doDisplay()
    #7 [Drupal root]/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling()
    #8 [Drupal root]/vendor/twig/twig/src/Template.php(379): Twig\Template->display()
    #9 [Drupal root]/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render()
    #10 [Drupal root]/web/core/themes/engines/twig/twig.engine(39): Twig\TemplateWrapper->render()
    #11 [Drupal root]/web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template()
    #12 [Drupal root]/web/core/lib/Drupal/Core/Render/Renderer.php(480): Drupal\Core\Theme\ThemeManager->render()
    #13 [Drupal root]/web/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender()
    #14 [Drupal root]/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(158): Drupal\Core\Render\Renderer->render()
    #15 [Drupal root]/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
    #16 [Drupal root]/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(159): Drupal\Core\Render\Renderer->executeInRenderContext()
    #17 [Drupal root]/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
    #18 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    #19 [Drupal root]/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
    #20 [Drupal root]/vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
    #21 [Drupal root]/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #22 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
    #23 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #24 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #25 [Drupal root]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\ContentLength->handle()
    #26 [Drupal root]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch()
    #27 [Drupal root]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup()
    #28 [Drupal root]/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #29 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle()
    #30 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #31 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #32 [Drupal root]/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #33 [Drupal root]/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #34 [Drupal root]/web/index.php(19): Drupal\Core\DrupalKernel->handle()
    #35 {main}
    

    So already closer to the intended beaviour :)

Production build 0.69.0 2024