Bug #23171 Fix is in Upcoming Release

Template Parsing Occasionally Fails

Version: 3.5.10 Reporter: borareed

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?

  • 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!

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

    borareed
    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!

    borareed
    07th July, 2017 at 4:32pm

You must be signed in to comment on a bug report.

  • 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;

ExpressionEngine News

#eecms, #events, #releases