Bug #23171 Bug Fixed

Template Parsing Occasionally Fails

Version: 3.5.10 Reporter: borareed

This is an archived bug report. If you are experiencing a similar issue, upgrade to the latest release and if that does not solve the problem, submit a new bug report

I have a few templates that do not render at all – the page loads completely blank (no PHP errors are shown, no matter the debug setting). They used to load on my EE2 site, but no longer do on EE3. (I am in the middle of taking a site from EE 2.9.0 to EE 3.5.10.) The root of the issue seems to be with how the template is parsed. This is from system/ee/EllisLab/ExpressionEngine/Library/Parser/Conditional/Parser.php

public function parse()

  while (count($this->tokens));


  $out = $this->closeBuffer(FALSE);

  return preg_replace('/^\n?(.*?)\n?$/is', '$1', $out);

For these templates that do not load, the preg_replace function returns null instead of a string. This comment from the PHP manual was helpful to me: http://php.net/manual/en/function.preg-replace.php#84285 Basically, I think there is too much content in the page markup, so the preg_replace command fails and returns NULL. I have tested out changing the regex to be not greedy (preg_replace('/^\n?(.*?)\n?$/isU', '$1', $out);) and the templates render successfully. Is it possible to changing the regex to be non-greedy site wide?

  • Hi borareed,

    Thanks for catching this. I’ve posted a solution to the bug. Would you mind testing and verifying that it fixes the bug?

    Seth Barber
    06th July, 2017 at 2:47pm
  • Yes, this does fix the issue! Thank you!

    06th July, 2017 at 3:25pm
  • As a follow up, now I get this PHP notice at the top of some pages:

    Notice Uninitialized string offset: 0 ee/EllisLab/ExpressionEngine/Library/Parser/Conditional/Parser.php, line 75

    So far I’ve seen it only on a page that’s using the Solspace Calendar module. Any ideas of why this could be happening? Or any way to get more information on this error?

    07th July, 2017 at 2:18pm
  • I’ve updated the solution. Can you re-apply and give it another try?

    Seth Barber
    07th July, 2017 at 3:20pm
  • It works! Thanks again!

    07th July, 2017 at 4:32pm
  • In system/ee/EllisLab/ExpressionEngine/Library/Parser/Conditional/Parser.php replace line 75 with:

    if ($out && $out[0] == "\n" && substr($out, -1) == "\n")
        $out = substr($out, 1);
        $out = substr($out, 0, strlen($out) - 1);
    return $out;
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases