From: Alexander Ebert Date: Mon, 21 Nov 2016 17:12:28 +0000 (+0100) Subject: Added work-around for broken controllers X-Git-Tag: 3.0.0_Beta_5~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=519f15c7700222357952e8cab41bbe960730c7fd;p=GitHub%2FWoltLab%2FWCF.git Added work-around for broken controllers --- 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; }