From 0ce4ae3ececf2cbb19c71e002c98d95af121988d Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 5 Jul 2024 03:16:53 +0000 Subject: [PATCH] Don't reuse the '$matches' array in 'RSSUtils::decode_srcset()'. This causes the size of the array to be incorrectly doubled due to the original regex match items being combined with the custom items (i.e. the ones with just 'url' and 'size' keys). Also rework 'RSSUtils::encode_srcset()' a bit so it looks similar to 'RSSUtils::decode_srcset()'. --- classes/RSSUtils.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php index 0ba2d18c4..10cfb6d43 100644 --- a/classes/RSSUtils.php +++ b/classes/RSSUtils.php @@ -2074,27 +2074,14 @@ class RSSUtils { $srcset, $matches, PREG_SET_ORDER ); - foreach ($matches as $m) { - array_push($matches, [ - "url" => trim($m["url"]), - "size" => trim($m["size"]) - ]); - } - - return $matches; + return array_map(fn(array $m) => ['url' => trim($m['url']), 'size' => trim($m['size'])], $matches); } /** * @param array> $matches An array of srcset subitem arrays with keys "url" and "size" */ static function encode_srcset(array $matches): string { - $tokens = []; - - foreach ($matches as $m) { - array_push($tokens, trim($m["url"]) . " " . trim($m["size"])); - } - - return implode(",", $tokens); + return implode(',', array_map(fn(array $m) => trim($m['url']) . ' ' . trim($m['size']), $matches)); } static function function_enabled(string $func): bool {