From 519f15c7700222357952e8cab41bbe960730c7fd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 21 Nov 2016 18:12:28 +0100 Subject: [PATCH] Added work-around for broken controllers --- .../builder/RoutingCacheBuilder.class.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php index b13416be82..360f5d9859 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php @@ -17,6 +17,16 @@ use wcf\util\FileUtil; * @since 3.0 */ class RoutingCacheBuilder extends AbstractCacheBuilder { + /** + * list of controllers violating the url schema, but are + * supported for legacy reasons + * @var array + */ + protected $brokenControllers = [ + 'lookup' => [], + 'reverse' => [] + ]; + /** * @inheritDoc */ @@ -73,12 +83,37 @@ class RoutingCacheBuilder extends AbstractCacheBuilder { // drop the last part containing `Action` or `Page` array_pop($parts); + // fix for invalid pages that would cause single character fragments + $sanitizedParts = []; + $tmp = ''; + $isBrokenController = false; + foreach ($parts as $part) { + if (strlen($part) === 1) { + $isBrokenController = true; + $tmp .= $part; + continue; + } + + $sanitizedParts[] = $tmp . $part; + $tmp = ''; + } + if ($tmp) $sanitizedParts[] = $tmp; + $parts = $sanitizedParts; + $ciController = implode('-', array_map('strtolower', $parts)); $className = $abbreviation . '\\' . ($libDirectory === 'lib/acp' ? 'acp\\' : '') . $pageType . '\\' . $filename; if (!isset($data['lookup'][$abbreviation])) $data['lookup'][$abbreviation] = ['acp' => [], 'frontend' => []]; $data['lookup'][$abbreviation][$libDirectory === 'lib' ? 'frontend' : 'acp'][$ciController] = $className; $data['reverse'][$filename] = $ciController; + + if ($isBrokenController) { + if (!isset($this->brokenControllers['lookup'][$abbreviation])) $this->brokenControllers['lookup'][$abbreviation] = []; + $this->brokenControllers['lookup'][$abbreviation][$ciController] = $className; + + if (!isset($this->brokenControllers['reverse'][$abbreviation])) $this->brokenControllers['reverse'][$abbreviation] = []; + $this->brokenControllers['reverse'][$abbreviation][preg_replace('~(?:Page|Form|Action)$~', '', $filename)] = $ciController; + } } } } @@ -148,6 +183,21 @@ class RoutingCacheBuilder extends AbstractCacheBuilder { } } + // masquerade broken controllers as custom urls + foreach ($this->brokenControllers as $type => $brokenControllers) { + foreach ($brokenControllers as $application => $controllers) { + foreach ($controllers as $key => $value) { + if (!isset($data[$type][$application])) { + $data[$type][$application] = []; + } + + if (!isset($data[$type][$application][$key])) { + $data[$type][$application][$key] = $value; + } + } + } + } + return $data; } -- 2.20.1