From 4f2d3f586ba6b7977c6d7333277309c02b849c6d Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 20 Jun 2017 19:18:30 +0200 Subject: [PATCH] Normalize csv in package installation plugins See #2311 --- .../AbstractMenuPackageInstallationPlugin.class.php | 5 +++-- ...bstractOptionPackageInstallationPlugin.class.php | 5 +++-- .../CronjobPackageInstallationPlugin.class.php | 3 ++- ...EventListenerPackageInstallationPlugin.class.php | 7 ++++--- .../OptionPackageInstallationPlugin.class.php | 7 ++++--- ...plateListenerPackageInstallationPlugin.class.php | 5 +++-- ...erGroupOptionPackageInstallationPlugin.class.php | 7 ++++--- ...ficationEventPackageInstallationPlugin.class.php | 5 +++-- .../UserOptionPackageInstallationPlugin.class.php | 7 ++++--- ...erProfileMenuPackageInstallationPlugin.class.php | 5 +++-- .../install/files/lib/util/StringUtil.class.php | 13 +++++++++++++ 11 files changed, 46 insertions(+), 23 deletions(-) diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php index ed0d92b6b7..eb6a89e7ef 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php @@ -2,6 +2,7 @@ namespace wcf\system\package\plugin; use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Abstract implementation of a package installation plugin for menu items. @@ -42,9 +43,9 @@ abstract class AbstractMenuPackageInstallationPlugin extends AbstractXMLPackageI 'menuItem' => $data['attributes']['name'], 'menuItemController' => isset($data['elements']['controller']) ? $data['elements']['controller'] : '', 'menuItemLink' => isset($data['elements']['link']) ? $data['elements']['link'] : '', - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', 'parentMenuItem' => isset($data['elements']['parent']) ? $data['elements']['parent'] : '', - 'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '', + 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '', 'showOrder' => $showOrder ]; } diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php index bc6680eb52..578129ecc0 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php @@ -3,6 +3,7 @@ namespace wcf\system\package\plugin; use wcf\data\package\Package; use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Abstract implementation of a package installation plugin for options. @@ -120,9 +121,9 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag // build data block with defaults $data = [ 'categoryName' => $element->getAttribute('name'), - 'options' => isset($data['options']) ? $data['options'] : '', + 'options' => isset($data['options']) ? StringUtil::normalizeCsv($data['options']) : '', 'parentCategoryName' => isset($data['parent']) ? $data['parent'] : '', - 'permissions' => isset($data['permissions']) ? $data['permissions'] : '', + 'permissions' => isset($data['permissions']) ? StringUtil::normalizeCsv($data['permissions']) : '', 'showOrder' => isset($data['showorder']) ? intval($data['showorder']) : null ]; diff --git a/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php index 005fe77042..a21133432d 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\cronjob\Cronjob; use wcf\data\cronjob\CronjobEditor; use wcf\system\WCF; use wcf\util\CronjobUtil; +use wcf\util\StringUtil; /** * Installs, updates and deletes cronjobs. @@ -76,7 +77,7 @@ class CronjobPackageInstallationPlugin extends AbstractXMLPackageInstallationPlu 'cronjobName' => isset($data['attributes']['name']) ? $data['attributes']['name'] : '', 'description' => isset($data['elements']['description']) ? $data['elements']['description'] : '', 'isDisabled' => isset($data['elements']['isdisabled']) ? intval($data['elements']['isdisabled']) : 0, - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', 'startDom' => $data['elements']['startdom'], 'startDow' => $data['elements']['startdow'], 'startHour' => $data['elements']['starthour'], diff --git a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php index 5e9d978306..3a73d9a942 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\event\listener\EventListener; use wcf\data\event\listener\EventListenerEditor; use wcf\system\cache\builder\EventListenerCacheBuilder; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes event listeners. @@ -73,13 +74,13 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat return [ 'environment' => isset($data['elements']['environment']) ? $data['elements']['environment'] : 'user', 'eventClassName' => $data['elements']['eventclassname'], - 'eventName' => $data['elements']['eventname'], + 'eventName' => StringUtil::normalizeCsv($data['elements']['eventname']), 'inherit' => isset($data['elements']['inherit']) ? intval($data['elements']['inherit']) : 0, 'listenerClassName' => $data['elements']['listenerclassname'], 'listenerName' => isset($data['attributes']['name']) ? $data['attributes']['name'] : '', 'niceValue' => $nice, - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', - 'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '' + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', + 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '' ]; } diff --git a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php index 75efcbd7a7..44feafe3ae 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php @@ -5,6 +5,7 @@ use wcf\data\option\OptionEditor; use wcf\data\package\Package; use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes options. @@ -40,13 +41,13 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP if (isset($option['optiontype'])) $optionType = $option['optiontype']; if (isset($option['defaultvalue'])) $defaultValue = WCF::getLanguage()->get($option['defaultvalue']); if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern']; - if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions']; + if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']); if (isset($option['showorder'])) $showOrder = intval($option['showorder']); if (isset($option['hidden'])) $hidden = intval($option['hidden']); $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); if (isset($option['selectoptions'])) $selectOptions = $option['selectoptions']; - if (isset($option['permissions'])) $permissions = $option['permissions']; - if (isset($option['options'])) $options = $option['options']; + if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']); + if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']); if (isset($option['supporti18n'])) $supportI18n = $option['supporti18n']; if (isset($option['requirei18n'])) $requireI18n = $option['requirei18n']; diff --git a/wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php index 3994472ffd..d424c53da5 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php @@ -3,6 +3,7 @@ namespace wcf\system\package\plugin; use wcf\data\template\listener\TemplateListenerEditor; use wcf\system\cache\builder\TemplateListenerCodeCacheBuilder; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes template listeners. @@ -57,8 +58,8 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal 'eventName' => $data['elements']['eventname'], 'niceValue' => $niceValue, 'name' => $data['attributes']['name'], - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', - 'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '', + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', + 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '', 'templateCode' => $data['elements']['templatecode'], 'templateName' => $data['elements']['templatename'] ]; diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php index d3d5cde666..3d173dd672 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\user\group\option\UserGroupOption; use wcf\data\user\group\option\UserGroupOptionEditor; use wcf\data\user\group\UserGroup; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes user group options. @@ -50,9 +51,9 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern']; if (!empty($option['showorder'])) $showOrder = intval($option['showorder']); $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); - if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions']; - if (isset($option['permissions'])) $permissions = $option['permissions']; - if (isset($option['options'])) $options = $option['options']; + if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']); + if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']); + if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']); if (isset($option['usersonly'])) $usersOnly = $option['usersonly']; // collect additional tags and their values diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php index 7c7277dcc5..9f130c8e4a 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\user\notification\event\UserNotificationEvent; use wcf\data\user\notification\event\UserNotificationEventEditor; use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes user notification events. @@ -66,8 +67,8 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI 'eventName' => $data['elements']['name'], 'className' => $data['elements']['classname'], 'objectTypeID' => $this->getObjectTypeID($data['elements']['objecttype']), - 'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '', - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', + 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '', + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', 'preset' => !empty($data['elements']['preset']) ? 1 : 0, 'presetMailNotificationType' => $presetMailNotificationType ]; diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php index cb31e0c156..588ce951e6 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php @@ -6,6 +6,7 @@ use wcf\data\user\option\UserOption; use wcf\data\user\option\UserOptionEditor; use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes user options. @@ -80,11 +81,11 @@ class UserOptionPackageInstallationPlugin extends AbstractOptionPackageInstallat if (isset($option['showorder'])) $showOrder = intval($option['showorder']); if (isset($option['outputclass'])) $outputClass = $option['outputclass']; if (isset($option['selectoptions'])) $selectOptions = $option['selectoptions']; - if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions']; + if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']); if (isset($option['isdisabled'])) $isDisabled = intval($option['isdisabled']); $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); - if (isset($option['permissions'])) $permissions = $option['permissions']; - if (isset($option['options'])) $options = $option['options']; + if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']); + if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']); // collect additional tags and their values $additionalData = []; diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php index efd52e7bb6..e81c49c83c 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php @@ -2,6 +2,7 @@ namespace wcf\system\package\plugin; use wcf\data\user\profile\menu\item\UserProfileMenuItemEditor; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Installs, updates and deletes user profile menu items. @@ -54,8 +55,8 @@ class UserProfileMenuPackageInstallationPlugin extends AbstractXMLPackageInstall // merge values and default values return [ 'menuItem' => $data['attributes']['name'], - 'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '', - 'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '', + 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '', + 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '', 'showOrder' => $showOrder, 'className' => $data['elements']['classname'] ]; diff --git a/wcfsetup/install/files/lib/util/StringUtil.class.php b/wcfsetup/install/files/lib/util/StringUtil.class.php index 5beea22275..4b80e6e3fc 100644 --- a/wcfsetup/install/files/lib/util/StringUtil.class.php +++ b/wcfsetup/install/files/lib/util/StringUtil.class.php @@ -764,6 +764,19 @@ final class StringUtil { return self::formatNumeric($number) . $unitPrefix; } + /** + * Normalizes a string representing comma-separated values by making sure + * that the separator is just a comma, not a combination of whitespace and + * a comma. + * + * @param string $string + * @return string + * @since 3.1 + */ + public static function normalizeCsv($string) { + return implode(',', ArrayUtil::trim(explode(',', $string))); + } + /** * Forbid creation of StringUtil objects. */ -- 2.20.1