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()'.
This commit is contained in:
wn_
2024-07-05 03:16:53 +00:00
parent 59cf218144
commit 0ce4ae3ece

View File

@@ -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<int, array<string, string>> $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 {