Просмотр исходного кода

Fixes #440 - Zend_Controller_Dispatcher_Abstract::_formatName() inconsistent with name handling

Frank Brückner 11 лет назад
Родитель
Сommit
40dd702da2

+ 5 - 1
library/Zend/Controller/Action/Helper/ViewRenderer.php

@@ -842,7 +842,11 @@ class Zend_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_
         $request    = $this->getRequest();
         $dispatcher = $this->getFrontController()->getDispatcher();
         $module     = $dispatcher->formatModuleName($request->getModuleName());
-        $controller = $request->getControllerName();
+        $controller = substr(
+            $dispatcher->formatControllerName($request->getControllerName()),
+            0,
+            -10
+        );
         $action     = $dispatcher->formatActionName($request->getActionName());
 
         $params     = compact('module', 'controller', 'action');

+ 34 - 0
tests/Zend/Controller/Action/Helper/ViewRendererTest.php

@@ -904,6 +904,40 @@ class Zend_Controller_Action_Helper_ViewRendererTest extends PHPUnit_Framework_T
         );
     }
 
+    /**
+     * @group GH-440
+     * @dataProvider providerControllerNameDoesNotIncludeDisallowedCharacters
+     */
+    public function testControllerNameDoesNotIncludeDisallowedCharacters($controllerName)
+    {
+        $this->request->setControllerName($controllerName)
+                      ->setActionName('index');
+
+        $this->helper->setActionController(
+            new Bar_IndexController(
+                $this->request, $this->response, array()
+            )
+        );
+
+        $this->assertEquals(
+            'index/index.phtml', $this->helper->getViewScript()
+        );
+    }
+
+    /**
+     * Data provider for testControllerNameDoesNotIncludeDisallowedCharacters
+     * @group GH-440
+     * @return array
+     */
+    public function providerControllerNameDoesNotIncludeDisallowedCharacters()
+    {
+        return array(
+            array('!index'),
+            array('@index'),
+            array('-index'),
+        );
+    }
+
     protected function _normalizePath($path)
     {
         return str_replace(array('/', '\\'), '/', $path);