We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Template Parsing Occasionally Fails

Development and Programming

borareed's avatar
borareed
17 posts
7 years ago
borareed's avatar borareed

Hi everyone,

I wasn’t quite sure which forum to put this in, but I am having issues parsing a few templates and wanted to see if anyone had the same issue. I have a few templates that do not render at all – the page loads completely blank. 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.) There are no PHP errors (setting “debug = 1” in index.php and admin.php do not make a difference) nor are there errors in the console.

I think I’ve tracked down the issue: it has to do 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 this a bug? Or would changing the regex to be non-greedy break other things on the site?

       
borareed's avatar
borareed
17 posts
7 years ago
borareed's avatar borareed

Turns out this was a bug: https://expressionengine.com/support/bugs/23171

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.