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()
 {
  $this->openBuffer();

  do
  {
   $this->next();
   $this->template();
  }
  while (count($this->tokens));

  $this->expect('EOS');

  $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?

  • 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