From c39081b6a11b980f07c562607a8558a321ddee33 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 1 May 2020 18:55:14 +0200 Subject: [PATCH] Fix bug in extracting required plugins from composer.json that led to spurious error in log (#7364) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_plugin_api.php | 28 +++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4a6a609c9..459ac35f4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ CHANGELOG Roundcube Webmail - Templates: Add support for nested if conditions (#6818) - Templates: Make [space][slash] ending of condition objects optional (#6954) - Fix so messages in threads with no root aren't displayed separately (#4999) +- Fix bug in extracting required plugins from composer.json that led to spurious error in log (#7364) RELEASE 1.4.4 ------------- diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index 7446829fa..3420dc136 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -245,7 +245,7 @@ class rcube_plugin_api /** * Get information about a specific plugin. - * This is either provided my a plugin's info() method or extracted from a package.xml or a composer.json file + * This is either provided by a plugin's info() method or extracted from a package.xml or a composer.json file * * @param string Plugin name * @return array Meta information about a plugin or False if plugin was not found @@ -316,17 +316,29 @@ class rcube_plugin_api if (!$info) { $composer = INSTALL_PATH . "/plugins/$plugin_name/composer.json"; if (is_readable($composer) && ($json = @json_decode(file_get_contents($composer), true))) { + // Build list of plugins required + $require = array(); + foreach (array_keys((array) $json['require']) as $dname) { + if (!preg_match('|^([^/]+)/([a-zA-Z0-9_-]+)$|', $dname, $m)) { + continue; + } + + $vendor = $m[1]; + $name = $m[2]; + + if ($name != 'plugin-installer' && $vendor != 'pear' && $vendor != 'pear-pear') { + $dpath = unslashify($dir->path) . "/$name/$name.php"; + if (is_readable($dpath)) { + $require[] = $name; + } + } + } + list($info['vendor'], $info['name']) = explode('/', $json['name']); $info['version'] = $json['version']; $info['license'] = $json['license']; $info['uri'] = $json['homepage']; - $info['require'] = array_filter(array_keys((array)$json['require']), function($pname) { - if (strpos($pname, '/') == false) { - return false; - } - list($vendor, $name) = explode('/', $pname); - return !($name == 'plugin-installer' || $vendor == 'pear-pear'); - }); + $info['require'] = $require; } // read local composer.lock file (once)