Added work-around for broken controllers
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Nov 2016 17:12:28 +0000 (18:12 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Nov 2016 17:12:28 +0000 (18:12 +0100)
wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php

index b13416be82401cdb91d8ea1ff16925eb6285299b..360f5d98597ac8e69ecbace236453a2fee71be82 100644 (file)
@@ -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;
        }