From 4624486d5648a37f23288d70ce9a210e576e75dc Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 9 Sep 2023 11:47:57 -0700 Subject: [PATCH] Fix use of mb_strpos() causing error when polyfill is used Error message: Uncaught ErrorException: iconv_strpos(): Detected an illegal character in input string in /var/www/site/vendor/symfony/polyfill-mbstring/Mbstring.php:536 --- src/Curl/Curl.php | 17 ++++++++++++++--- src/Curl/MultiCurl.php | 0 2 files changed, 14 insertions(+), 3 deletions(-) mode change 100755 => 100644 src/Curl/MultiCurl.php diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index ca0159b..0dd90f6 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -1937,16 +1937,27 @@ class Curl extends BaseCurl // Ensure that the server says the response is compressed with // gzip and the response has not already been decoded. Use // is_string() to ensure that $response is a string being passed - // to mb_strpos() and gzdecode(). + // to mb_strpos() and gzdecode(). Use extension_loaded() to + // ensure that mb_strpos() uses the mbstring extension and not a + // polyfill. isset($response_headers['Content-Encoding']) && $response_headers['Content-Encoding'] === 'gzip' && is_string($response) && - mb_strpos($response, "\x1f" . "\x8b" . "\x08", 0, 'US-ASCII') === 0 + ( + ( + extension_loaded('mbstring') && + mb_strpos($response, "\x1f" . "\x8b" . "\x08", 0, 'US-ASCII') === 0 + ) || + !extension_loaded('mbstring') + ) ) || ( // Or ensure that the response looks like it is compressed with // gzip. Use is_string() to ensure that $response is a string - // being passed to mb_strpos() and gzdecode(). + // being passed to mb_strpos() and gzdecode(). Use + // extension_loaded() to ensure that mb_strpos() uses the + // mbstring extension and not a polyfill. is_string($response) && + extension_loaded('mbstring') && mb_strpos($response, "\x1f" . "\x8b" . "\x08", 0, 'US-ASCII') === 0 ) ) { diff --git a/src/Curl/MultiCurl.php b/src/Curl/MultiCurl.php old mode 100755 new mode 100644