wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

PHP fatal error potentially related to ATF and picture tags

Open joejoe04 opened this issue 1 year ago • 2 comments

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version ✅
  • Used the search feature to ensure that the bug hasn’t been reported before ✅

Describe the bug After upgrading to version 3.16, user reported site went down and the following error was logged:

"PHP Fatal error: Uncaught TypeError: ltrim(): Argument #1 ($string) must be of type string, null given in /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php:222 Stack trace: #0 /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php(222): ltrim(NULL, '/') #1 [internal function]: WP_Rocket\Engine\Media\AboveTheFold\Frontend\Controller->WP_Rocket\Engine\Media\AboveTheFold\Frontend\{closure}(false) #2 /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media"

In the Slack discussion, Remy said he thought it may be related to:

  • how the <picture> tag is being handled.
  • Safeguards related to handling exclusions

Expected behavior The error should not occur for all valid <picture> tag markup.

Additional context Ticket - https://secure.helpscout.net/conversation/2605875796/493242/ Website - https://creatureartteacher.com Slack - https://wp-media.slack.com/archives/C43T1AYMQ/p1716485105461249

Acceptance Criteria (for WP Media team use only) Clear instructions for developers, to be added before the grooming

joejoe04 avatar May 24 '24 16:05 joejoe04

Hello,

We have the same problem on our client's website, here is an example https://www.escoffier.edu/about/chef-instructors/albert-schmid/. Is it possible to get it fixed?

pavel-burminsky avatar Jun 08 '24 13:06 pavel-burminsky

Related: https://secure.helpscout.net/conversation/2662969109/504678/

joejoe04 avatar Jul 26 '24 19:07 joejoe04

Scope a solution ✅

We need to safeguard exclusion for empty path or path that aren't valid. Before the return here we can add a check for the $exclusion['path'] if it's set.

if ( isset( $exclusion['path'] ) && is_string( $exclusion['path'] ) ) {
      return ltrim( $parsed_url['path'], '/' );
}
//Return empty string if not set.
return '';

Estimate the effort

Effort XS

Khadreal avatar Jan 27 '25 07:01 Khadreal

Looks ok to me

Miraeld avatar Jan 28 '25 01:01 Miraeld