cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
500 stars 48 forks source link

Fatal error: Uncaught TypeError: preg_replace(): #165

Closed raphaelparent closed 2 years ago

raphaelparent commented 2 years ago

I'm trying to configure Satispress on DigitalOcean wordpress droplet (running with apache) and I've got most of it working except the composer download. It returns this error.

Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading raphparent-packages/advanced-custom-fields-pro (5.10.2)
  - Downloading raphparent-packages/advanced-custom-fields-pro (5.10.2)
  - Downloading raphparent-packages/advanced-custom-fields-pro (5.10.2)
  - Downloading raphparent-packages/advanced-custom-fields-pro (5.10.2)

  [Composer\Downloader\TransportException]                                                                     
  The "https://packages.raphparent.website/satispress/advanced-custom-fields-pro/5.10.2" file could not be do  
  wnloaded (HTTP/1.1 500 Internal Server Error)         

And when I try to access the url in my browser I get this

Fatal error: Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, bool given in /var/www/html/wp-content/plugins/satispress/src/Provider/RequestHandler.php:149 

Stack trace: 
#0 /var/www/html/wp-content/plugins/satispress/src/Provider/RequestHandler.php(149): preg_replace() 
#1 /var/www/html/wp-content/plugins/satispress/src/Provider/RequestHandler.php(162): SatisPress\Provider\RequestHandler->send_header() 
#2 /var/www/html/wp-content/plugins/satispress/src/Provider/RequestHandler.php(102): SatisPress\Provider\RequestHandler->send_headers() 
#3 /var/www/html/wp-includes/class-wp-hook.php(303): SatisPress\Provider\RequestHandler->dispatch() 
#4 /var/www/html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() 
#5 /var/www/html/wp-includes/plugin.php(518): WP_Hook->do_action() 
#6 /var/www/html/wp-includes/class-wp.php(388): do_action_ref_array() 
#7 /var/www/html/wp-includes/class-wp.php(750): WP->parse_request() 
#8 /var/www/html/wp-includes/functions.php(1291): WP->main() 
#9 /var/www/html/wp-blog-header.php(16): wp() 
#10 /var/www/html/index.php(17): require('...') #11 {main} thrown in /var/www/html/wp-content/plugins/satispress/src/Provider/RequestHandler.php on line 149

I have managed to debug it and see that the error is caused by a invalid header. The Last-Modified header is set to false instead of a date. I have not been able to find out why that is. This is reaching out of my knowledge so I'm asking here for help.

Here's the function where it happens

protected function send_header( string $name, $value ) {
    /*
     * Sanitize as per RFC2616 (Section 4.2):
     *
     * Any LWS that occurs between field-content MAY be replaced with a
     * single SP before interpreting the field value or forwarding the
     * message downstream.
     */
    $value = preg_replace( '/\s+/', ' ', $value );
    header( sprintf( '%s: %s', $name, $value ) );
}

Everything I've tried within that function breaks the url which return an ERR_INVALID_RESPONSE code.

Thanks!

raphaelparent commented 2 years ago

Downgrading to PHP 7.4 solved the issue for me. Leaving open since this is still an issue.

aksld commented 2 years ago

Hello,

Any news for this issue ? Imposible to use SatisPress on a server with php 8.

slam-campup commented 1 year ago

I'm having this issue, only at RequestHandler.php:149. See ticket #195

I thought it was due to changing domains, but I also updated to PHP 8 at the same time.