From d35e9645980dbf91b49e2bb260b0621a5df69a6a Mon Sep 17 00:00:00 2001
From: Ernesto Baschny <ernst@cron-it.de>
Date: Mon, 14 Oct 2013 12:02:30 +0200
Subject: [PATCH] [BUGFIX] No exception if uninstalled extension has an invalid
 key

The loop that scans for packages should skip those whose key is not
valid, in order to avoid an exception later down the road.

Resolves: #52779
Releases: 6.2
Change-Id: Ic9903b7d69fd6c9b9581e85d2f6ea1222ebb8885
Reviewed-on: https://review.typo3.org/24728
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Thomas Maroschik
Tested-by: Thomas Maroschik
---
 typo3/sysext/core/Classes/Package/Package.php     |  2 +-
 .../core/Classes/Package/PackageManager.php       | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/core/Classes/Package/Package.php b/typo3/sysext/core/Classes/Package/Package.php
index 29b1b1a04daa..138916b03dc7 100644
--- a/typo3/sysext/core/Classes/Package/Package.php
+++ b/typo3/sysext/core/Classes/Package/Package.php
@@ -19,7 +19,7 @@ namespace TYPO3\CMS\Core\Package;
  */
 class Package extends \TYPO3\Flow\Package\Package implements PackageInterface {
 
-	const PATTERN_MATCH_EXTENSIONKEY = '/^[0-9a-z_]+$/i';
+	const PATTERN_MATCH_EXTENSIONKEY = '/^[0-9a-z_-]+$/i';
 
 	/**
 	 * @var array
diff --git a/typo3/sysext/core/Classes/Package/PackageManager.php b/typo3/sysext/core/Classes/Package/PackageManager.php
index a79ef15ab95b..9f11edfe5890 100644
--- a/typo3/sysext/core/Classes/Package/PackageManager.php
+++ b/typo3/sysext/core/Classes/Package/PackageManager.php
@@ -59,7 +59,7 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 	protected $packageAliasMap = array();
 
 	/**
-	 *
+	 * Constructor
 	 */
 	public function __construct() {
 		$this->packagesBasePaths = array(
@@ -170,7 +170,7 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 	protected function saveToPackageCache() {
 		$cacheEntryIdentifier = $this->getCacheEntryIdentifier();
 		if ($cacheEntryIdentifier !== NULL && !$this->coreCache->has($cacheEntryIdentifier)) {
-			$cacheEntryPath = rtrim($this->coreCache->getBackend()->getCacheDirectory(), '/\\');
+			$cacheEntryPath = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::fixWindowsFilePath($this->coreCache->getBackend()->getCacheDirectory()), '/');
 			// Package objects get their own cache entry, so PHP does not have to parse the serialized string
 			$packageObjectsCacheEntryIdentifier = uniqid('PackageObjects_');
 			// Build cache file
@@ -275,10 +275,11 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 				$this->composerNameToPackageKeyMap[strtolower($composerManifest->name)] = $packageKey;
 				$this->packageStatesConfiguration['packages'][$packageKey]['manifestPath'] = substr($composerManifestPath, strlen($packagePath)) ? : '';
 				$this->packageStatesConfiguration['packages'][$packageKey]['composerName'] = $composerManifest->name;
-			}
-			catch (\TYPO3\Flow\Package\Exception\MissingPackageManifestException $exception) {
+			} catch (\TYPO3\Flow\Package\Exception\MissingPackageManifestException $exception) {
 				$relativePackagePath = substr($packagePath, strlen($packagesBasePath));
 				$packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1);
+			} catch (\TYPO3\Flow\Package\Exception\InvalidPackageKeyException $exception) {
+				continue;
 			}
 			if (!isset($this->packageStatesConfiguration['packages'][$packageKey]['state'])) {
 				$this->packageStatesConfiguration['packages'][$packageKey]['state'] = 'inactive';
@@ -290,7 +291,8 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 			$this->packageStatesConfiguration['packages'][$packageKey]['classesPath'] = \TYPO3\Flow\Package\Package::DIRECTORY_CLASSES;
 		}
 
-		$this->registerPackagesFromConfiguration(!empty($this->packages));
+		$registerOnlyNewPackages = !empty($this->packages);
+		$this->registerPackagesFromConfiguration($registerOnlyNewPackages);
 		if ($this->packageStatesConfiguration != $previousPackageStatesConfiguration) {
 			$this->sortAndsavePackageStates();
 		}
@@ -359,6 +361,9 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 			} catch (\TYPO3\Flow\Package\Exception\InvalidPackagePathException $exception) {
 				$this->unregisterPackageByPackageKey($packageKey);
 				continue;
+			} catch (\TYPO3\Flow\Package\Exception\InvalidPackageKeyException $exception) {
+				$this->unregisterPackageByPackageKey($packageKey);
+				continue;
 			}
 
 			$this->registerPackage($package, FALSE);
-- 
GitLab